Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用servlet将HTML页面重定向到另一个页面_Java_Html_Servlet 3.0 - Fatal编程技术网

Java 使用servlet将HTML页面重定向到另一个页面

Java 使用servlet将HTML页面重定向到另一个页面,java,html,servlet-3.0,Java,Html,Servlet 3.0,我使用了这个方法,并且注释了一次,但是它不起作用,print方法工作正常,但是重定向没有起作用 else if (action.contentEquals("Login")) { RequestDispatcher view = request.getRequestDispatcher("mainPage.html"); try { System.out.print("Login now");

我使用了这个方法,并且注释了一次,但是它不起作用,print方法工作正常,但是重定向没有起作用

        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");      }
        */
    }

你可以在这里得到一些想法:


如果您使用的是servlet,为什么不使用jsp或jsf而不是html呢?您是否尝试过在
view.forward(…)
之后登录,看看控件是否到达那里。如果是这样,那么肯定是出了问题。如果可能的话,给出整个控制器代码,也许错误就在那里,我该怎么办,请帮助
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");
    }