gpt4 book ai didi

java - Servlet 重定向到空白页

转载 作者:行者123 更新时间:2023-12-02 09:25:28 25 4
gpt4 key购买 nike

每当我点击submit时它重定向到空白页面,但 url 工作正常我对我的响应标签是否错误感到困惑

代码:

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);

关于java - Servlet 重定向到空白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58371037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com