This question already has an answer here:
Submitting form to Servlet which interacts with database results in blank page
                            
                                (1个答案)
                            
                    
                7个月前关闭。
        

    

每当我单击submit时,它将重定向到空白页,但该网址可以正常工作
我对我的响应标签是否错误感到困惑

码:

protected void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException {
    Connection con=connector.getConnection();
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    String message = null;
    String url = null;
   try {
        PreparedStatement ps = con.prepareStatement( "Select * from data Where username=?'" + username + "' and password=?'" + password + "';");
        ps.setString(1, request.getParameter("username"));
        ps.setString(2, request.getParameter("password"));
        ResultSet rs = ps.executeQuery();
               if(rs.next()) {
               RequestDispatcher rd=request.getRequestDispatcher("practice1.jsp");
               rd.forward(request,response);

               }
               else {
               message="Invalid Input Please Try Again";
             request.setAttribute("message", message);
             request.setAttribute("url", url);

           }
   }


   catch(SQLException ex){
    message="ERROR"+ex.getMessage();
    ex.printStackTrace();
}


请让我知道我想念的东西。

最佳答案

尝试通过更改以下代码来修复它:

之前:

PreparedStatement ps = con.prepareStatement( "Select * from data Where username=?'" + username + "' and password=?'" + password + "';");
ps.setString(1, request.getParameter("username"));
ps.setString(2, request.getParameter("password"));


后:

PreparedStatement ps = con.prepareStatement( "Select * from data Where username=? and password=?");
ps.setString(1, username);
ps.setString(2, password);

08-18 16:51