[每当我单击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);