Forwarding vs redirection in Java

Source: Internet
Author: User

What is the Holy Spirit of forwarding and redirection? Before just know it is to solve the page jump problem. Learn from the DRP by stepping through it . There are more and more applications for them.

And then you bring yourself a lot of other questions? What does it have to be ?

How to use it? What is the difference between this and the page jump in ASP. Next, the two of them to the system of learning it!

First, what is it?

Forwarding:After the server receives a request from the client, the server hands over the control to a JSP page, and the new JSP page receives the request, depending on whether the situation continues to transfer control or display the page itself. The entire process of displaying the page at the end is a page jump process. In this process, the server is able to transfer the requested data over the page without worrying about the loss of the data

redirect : After the server receives a browser client request, the server sends a new link to the client browser. After the browser receives the new link and then requests the link address again, after the entire process completes in the client browser appears to have the jump, actually is the client browser requests two times, therefore in the browser's address bar The network address naturally will change to the new connection

Second, what to do?

in the Java Development of Two types of JSP Jump, the end of the Web application from one page to the question of a page.

Third, when to use?

forwarding is usually faster and can keep objects within the request. and the user's request content needs to be processed by the server in case of the available forwarding.

Let's say that you just want to finish the page jump, and do not want to refresh when you submit the current page again then use redirection.

Four, how to use?

forwarding :

Request.getrequestdispatcher (".. /ok.html "). Forward (Request,response);

 // address does not change ; the data for the form ok.html can also obtain ; server jumps are equivalent to POST Way

redirect :

Response.sendredirect (".. /error.html ");

// Address Change ; the data for the form error.html not be able to get ; client jump is equivalent to GET Way

V. Control

The prime Minister looks at the following two images to be able to make very clear the difference between forwarding and redirection:

Figure One: Forwarding


figure II: Redirection

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbgl1x3l1amllmjaxmwnvbq==/font/5a6l5l2t/fontsize/400/fill/ I0jbqkfcma==/dissolve/70/gravity/center ">

1 , number of server requests

Forwarding is a user request that may go through n JSP pages and return to the user's browser once. is the process of requesting multiple processing at a time

redirect is a total of two requests for server

2 , changes in links during a jump

Forwarding during a jump the browser requests the server once. Server through the N JSP page does not change the requested link address, because the user only requested once, so throughout the jump process the link address is not changed, in the browser's address bar can be seen

Redirect has requested two servers in the jump and is two different link addresses that can be seen in the browser's address bar two times is changed

3 , different purposes

forwarding is the server to get the user's request content and need to do part of the processing

redirection is simply a simple way for users to access a new link

4 , different range

Forwarding can only forward requests to components in the same Web application

redirection is not only able to redirect to other resources in the current application. Also be able to redirect resources to other applications on the same site, even resources that redirect to other sites using absolute URLs

5 , browser address is different

After the forwarding process is complete, the browser address remains the original URL address unchanged

after the redirected access process is finished, the URL that appears in the browser's address bar changes, and the destination URL is changed from the initial address to the redirect

Vi. Summary

to summarize, either forward or redirect before they are called. None of the content has actually been output to the client, Assuming there is something in the buffer that will be purged from the buffer.

by learning about forwarding and redirection above, the next task is to look at how it differs from the page jump for ASP.

Forwarding vs redirection in Java

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.