Servlet:
Of course, in servlets, jumps generally occur in doGet, doPost and other methods.
1) redirect method
response.sendRedirect("/a.jsp");
The path to the page is a relative path. sendRedirect can jump to any page, not necessarily limited to this web application, such as:
response.sendRedirect("//www.VeVB.COm");
The browser address bar changes after the jump.
If you want to pass the value in this way, you can only bring the parameter in the URL or put it in the session. You cannot use request.setAttribute to pass it.
2) forward method
RequestDispatcher dispatcher = request.getRequestDispatcher("/a.jsp");
dispatcher .forward(request, response);
The path to the page is a relative path. The forward method can only jump to pages in this web application.
The browser address bar will not change after the jump.
Using this method to jump, you can use three methods to pass values: parameter, session, request.setAttribute in the URL
JSP:
1) response.sendRedirect();
The same method as servlet's response.sendRedirect().
Out.flush() is not allowed before this statement. If there is, an exception will occur:
java.lang.IllegalStateException: Can't sendRedirect() after data has committed to the client.
at com.caucho.server.connection.AbstractHttpResponse.sendRedirect(AbstractHttpResponse.java:558)
...
Browser address bar changes after jump
If you want to jump to a different host, after the jump, the statements following this statement will continue to execute, as if a new thread has been opened, but the operation of response is meaningless;
If you want to jump to the same host, the jump will not occur until the statements following this statement are executed;
2) response.setHeader("Location","");
Out.flush() is not allowed before this statement. If there is, the page will not jump.
Browser address bar changes after jump
The jump will not occur until the statements following this statement are executed.