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))