暮蓁 2020-03-28 11:23 采纳率: 0%
浏览 1459

求助JSP出现异常The server encountered an internal error that prevented it from fulfilling this request.该怎么解决?

求大神帮忙!
报错信息如下:

图片说明
报错页面checkUser.jsp代码:

<%@ page language="java" import="java.sql.*" contentType="text/html; charset=gbk" pageEncoding="gbk"%>
<jsp:useBean id="dbcon" class="bean.DBcon" scope="request"/>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>查验</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>

  <body>
    <%String name=request.getParameter("name");
      String pwd=request.getParameter("password");
      Connection dbCon=dbcon.getConnection();
      Statement stmt=dbCon.createStatement();
      ResultSet rs=stmt.executeQuery("select * from userinfo where loginname="+name+" and password="+pwd);
      rs.last();
      if(rs.next()){
          session.setAttribute("name", "用户名");
          session.setAttribute("pwd","密码");
          response.sendRedirect("main.jsp");
          }else{
          response.sendRedirect("index.html");
          }
       rs.close();
       stmt.close();
       dbCon.close();
     %>
  </body>
</html>

报错语句为Statement stmt=dbCon.createStatement();
但是真的不知道哪里错了呀

JavaBean——DBcon.java代码

package bean;
import java.sql.*;

public class DBcon {
    private static final String DRIVER_CLASS="com.mysql.jdbc.Driver";
    private static final String DATABASE_URL="jdbc:mysql://localhost:3306/books?useUnicode=true&characterEncoding=UTF-8";
    private static final String DATABASE_USER="root";
    private static final String DATABASE_PASSWORD="admin";
    public static Connection getConnection(){
        Connection dbConnection=null;
        try{
            Class.forName(DRIVER_CLASS);
            dbConnection=DriverManager.getConnection(DATABASE_URL, DATABASE_USER, DATABASE_PASSWORD);
        }catch(Exception e){
            e.printStackTrace();
        }
        return dbConnection;
    }
    public static void closeConnection(Connection dbConnection){
        try{
            if(dbConnection!=null&&(!dbConnection.isClosed())){
                dbConnection.close();
            }
        }catch(SQLException sqlEx){
            sqlEx.printStackTrace();
        }
    }
    public static void closeResultSet(ResultSet res){
        try{
            if(res!=null){
                res.close();
                res=null;
            }
        }catch(SQLException e){
            e.printStackTrace();
        }
    }
    public static void closeStatement(PreparedStatement pStatement){
        try{
            if(pStatement!=null){
                pStatement.close();
                pStatement=null;
            }
        }catch(SQLException e){
            e.printStackTrace();
        }
    }

}

求大神帮忙!

  • 写回答

1条回答

  • threenewbee 2020-03-28 14:05
    关注

    dbcon.getconnection()失败了,检查数据库地址、用户名密码、端口和配置

    评论

报告相同问题?

悬赏问题

  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多