Java Web redirection and forwarding

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.