求助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个回答

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

qq_44738660
暮蓁 检查过了,没有问题
7 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐