暮蓁 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()失败了,检查数据库地址、用户名密码、端口和配置

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮