First define these two words:
Redirection is directing a user from the current page or servlet to another JSP page or servlet
Forwarding is the forwarding of a user's request to the current JSP page or Servlet object to another JSP page or Servlet object.
In the Servlet class, you can use the redirection method of the HttpServletResponse class Sendredirect ()
You can also use the RequestDispatcher class's forwarding method, forward ().
The following are the differences between the two:
1) RequestDispatcher's forward () method can only forward requests to components in the same Web application, Hpptservletresponse's Sendredirect () method is not only redirected to the current
Other resources in the application can also be redirected to resources in other applications at the same site, even to resources that are redirected to other sites using an absolute URL. If passed to the Sendredirect () method
The relative URL begins with a "/", which is relative to the root of the entire Web site, and if the relative URL that is created when the RequestDispatcher object starts with "/", it is relative to the root directory of the current Web application.
2) When the access process redirected using the Sendredirect () method ends, the URL displayed in the browser's address bar changes, changing from the initial URL address to the redirected target URL;
After the request forwarding process of the-dispatcher ForWord () method ends, the browser's address bar remains the initial URL address unchanged.
Java Web redirection and forwarding