Redirect (client redirection) and dispatch (server-side redirection)

Source: Internet
Author: User
These two concepts are often put together for comparison. Let's review these two concepts today. The former occurs on the client (browser), and the latter occurs on the server, therefore, some people refer to the former as client redirection and the latter as server-side redirection, although this title is not appropriate for the latter. Original article link: http://blog.csdn.net/bluishglc/article/details/7953614 reprint please indicate the source! Redirect (client redirection)In the standard sense, "redirection" refers to HTTP redirection, which is a mechanism stipulated by the HTTP protocol. This mechanism works like this: when the client sends a request to the server requesting a resource, the server receives the request and finds that the requested resource is actually stored in another location, therefore, the server writes the correct URL of the requested resource in the returned response, and sets the reponse status code to 301 (indicating that this is a response that requires browser redirection ), after the client receives the response, it will re-initiate the request based on the new URL. There is a typical feature of redirection, that is, when a request is redirected, the URL displayed on the browser is often no longer the one requested at the beginning. This is the origin of redirection. A typical application of HTTP redirection is to prevent repeated submission of forms. The principle is: if a user information editing page is used, the form is submitted to saveuser through post. action. After the request is submitted, a redirected response can be returned. The address can be viewuser. action, that is, directed to the user details page (cannot be modified or submitted ). Of course, this method prevents repeated page submissions. If the user returns the form page, resubmit the form, or before the user arrives at the server side, click the submit button multiple times (you can control the number of times the submit button is clicked through JavaScript. In servlet, the method to implement client redirection is: Response. sendredirect () Dispatch (server-side redirection)Dispatch (forward) refers to the process in which the server entrusts multiple servlets or JSP servers to take over for processing the request. The most common is that a servlet is used for processing (such as computing the business logic), and then forward is used to render the view for a JSP. In servlet, the implementation of dispatch is implemented through requestdispatchers. This class has two methods: one is forward and the other is include, there are two tags for implementing dispatch in JSP: <JSP: forward/> and <JSP: Include/>.  Whether it is forward or include, we can clearly see that the request and reponse are always transmitted from a servlet or JSP to another servlet or JSP, this is the key for the server to implement the dispatch mode. In other words, we can regard request and reponse as a kind of resource. A series of servlets and JSP are computing within their scope of responsibility based on the same resource.

Note: The Source image is derived from head first servlets and JSP.

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.