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

标签 java html servlet-3.0

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

        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/

相关文章:

html - 需要帮助,CSS 和 WORDPRESS

java - WebSphere 8,web.xml 版本 ="3.0",默认 servlet 映射?

java - Java GC 是否会释放数组的 null 元素?

javascript - 对齐文本插件 bootstrap html

java OOM 关于创建 2 个 10 亿个整数的数组

python - 使用flask根据python传递的数据更改html图像

java - Glassfish - 上传图片 - 做对了

java - 如何限制 tomcat/java Web 服务器世界中每个路由的最大线程

java - 为什么查询 Androids MediaStore 返回空光标?

Java 为什么我需要最小化然后重新加载?