为什么这段代码没有跳转到chat.jsp这是验证文件?

时间:2018-10-15 19:58:03

标签: jsp login

<%@page contentType="text/html" pageEncoding="UTF-8"%>   
<%@page import="java.io.PrintWriter"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.*"%>
<!DOCTYPE html>
 <html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Verification</title>
   </head>
    <body>

    <%
     String driver ="com.mysql.jdbc.Driver";
     String database = "login";


     response.setContentType("text/html");
     try {
    Class.forName(driver);
        } catch (ClassNotFoundException e) {
    e.printStackTrace();
        }
     Connection con = null;
     Statement statement = null;
    ResultSet resultSet = null;

    String uname = request.getParameter("username").toString();
    String pass = request.getParameter("password").toString();

      try {
    Class.forName(driver);
            Connection conn = 
     DriverManager.getConnection("jdbc:mysql://localhost:3306/abc? 
     zeroDateTimeBehavior=convertToNull [root on Default schema]", "root", 
      "");
             statement = conn.createStatement();
            String query = "select *from chatting where username ='" + uname 
            +"' and password='" + pass+ "';";
                resultSet  = statement.executeQuery(query);

                    if( resultSet.next())
                    {      
                           request.getSession();
            session.setAttribute("uname", uname);
            session.setAttribute("pass1", pass);
                       response.sendRedirect("chat.jsp");
                    }
                    else
                    {
                        response.sendRedirect("error.jsp");
                    }
      }

        catch (Exception e) {
        System.out.println("Error in connection");
        e.printStackTrace();
       }

       %>
    </body>
   </html>

我是jsp的新手,所以这可能是错误的,但是在哪里出错,在chrome浏览器控制台上没有看到错误,但是Submit按钮没有使其跳转到其他页面,我还没有使用过Java bean或Java类 请帮帮我,我也不想使用java bean 如果可以的话,可以将这两个jsp文件都加入其中,请包括以下步骤

0 个答案:

没有答案