暮蓁 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 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案