我使用了这个方法并评论了一次,但它不起作用,打印方法工作正常,但重定向不起作用。
else if (action.contentEquals("Login"))
{
RequestDispatcher view = request.getRequestDispatcher("mainPage.html");
try {
System.out.print("Login now");
view.forward(request, response);
} catch (ServletException e1) {
System.out.print("Error Loging in");
}
/*try {
System.out.print("Login now");
response.sendRedirect("mainPage.html");
return;
} catch (IOException e) {
System.out.print("Error"); }
*/
}
最佳答案
您可以在这里获得一些想法:
Redirecting a calling JSP to itself using RequestDispatcher object
RequestDispatcher view = request.getRequestDispatcher("mainPage.html");
try {
System.out.print("Login now");
view.forward(request, response);
response.sendRedirect("mainPage.html");
} catch (ServletException e1) {
System.out.print("Error Loging in");
}
关于java - 使用 servlet 将 HTML 页面重定向到另一页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60488256/