The difference between Java forwarding and redirection _java

Source: Internet
Author: User

There is an important difference between redirection and forwarding: When forwarding is used, the JSP container uses an internal method to invoke the target page, and the new page continues to process the same request, and the browser will not know about the process. In contrast, the redirection means that the first page notifies the browser to send a new page request. Because, when you use redirection, the URL displayed in the browser becomes the URL of the new page, and when you use forwarding, the URL stays the same. Redirection is slower than forwarding because the browser has to issue a new request. Also, because of a new request being redirected, the objects within the request will not be available after a redirect.

How do you choose to redirect or forward? Forwarding is usually faster and can keep objects within the request, so he is the first choice. However, since the URL in the browser still points to the start page after forwarding, the start page will be called back if the current page is overloaded. If you do not want to see such a situation, select forward.

The difference between forwarding and redirection

Instead of using the session scope just to pass the variable to the next page, it will increase the scope of the variable for no reason, and forwarding may help you to solve the problem.

Redirect: variables stored in previous request are all invalidated and entered a new request scope.
Forwarding: The variables stored in previous request will not fail, just like putting two pages together.

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.