The difference between redirection and request forwarding in Javaweb (Response.sendredirect () and Request.getrequestdispatcher (Rul). Forward (Request,response))

Source: Internet
Author: User

First two pictures, easy to understand:

As you can see, when redirected, the server re-sends a response command to the viewer, allowing the viewer to send a request again to Url2 to get URL2 resources

When the request is forwarded, similar to the server itself sent a jump, and then the results directly to the browser, which is also asked what the browser will not change the URL address. Here is a concrete summary of their differences

One, Response.sendredirect (URL)- the server sends a new URL to the browser, and the viewer then requests it based on the new URL

Request.getrequestdispatcher (URL). Forward (Request,response); the request is forwarded to the specified URL (Intra-server jump URL then send the results to the viewer)

Second, response.sendredirect (URL)-- client Jump

Request.getrequestdispatcher (URL). Forward (Request,response)-- server Jump

Third,response.sendredirect (URL)-- jump to the specified URL address, the last page of the request will end, requests the object will die and the data will die.

Request.getrequestdispatcher (URL). Forward (Request,response)-- internal jump,request object always exists

Iv. response.sendredirect (URL)--the URL will change

Request.getrequestdispatcher (URL). Forward (Request,response)-- in the viewer's point of view, he just sends a request Then receive a response, so the URL does not change

Five, Response.sendredirect (URL)--parameters need to be added after the URL .

Request.getrequestdispatcher (URL). Forward (Request,response)- pass parameters you can manipulate the request object method SetAttribute ("name", value)

Six, Response.sendredirect (URL)- can be targeted to any URL

Request.getrequestdispatcher (URL). Forward (Request,response)- can only navigate to server resources

VII, Response.sendredirect (URL)-- can redirect the jsp file with frame

Resquest.getrequestdispatcher (URL). Forward (Request,response)- You cannot redirect a JSP with a frame file, which can be directed to an HTML file that has a frame and can be called only if the client does not have output forward method, if the current page buffer is not empty, then the sentence may not work because the commit does not change the URL address, and the refresh repeats the commit.

The difference between redirection and request forwarding in Javaweb (Response.sendredirect () and Request.getrequestdispatcher (Rul). Forward (Request,response))

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.