gpt4 book ai didi

java - 使用 servlet 将 HTML 页面重定向到另一页面

转载 作者:行者123 更新时间:2023-12-01 18:09:46 26 4
gpt4 key购买 nike

我使用了这个方法并评论了一次,但它不起作用,打印方法工作正常,但重定向不起作用。

        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/

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