Redirection and forwarding in the Web

Source: Internet
Author: User

Redirect: Redirect (client-side redirection)is a mechanism provided by the HTTP protocol: When a client sends a request to the server requesting a resource, the server finds the requested resource in a different location after it receives the request. The server then writes the correct URL for 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), When the client accepts the response, the request is re-initiated based on the new URL. Redirection has a typical syndrome, that is, when a request is redirected, the URL that is displayed on the final browser is no longer the URL that was requested at the beginning. in the servlet, the method of implementing client redirection is: Response.sendredirect ().
Dispatch (Forward): Forward ( also known as Server end multiplicity orientation ) Dispatch (Forward)refers to the process by which the server will delegate the request to multiple Servlets or JSP replacements during the process of request processing. The most common is to first be processed by a servlet (for example, to compute the business logic) and then forward to render the view for a JSP. In the servlet, the implementation of dispatch is achieved through the requestdispatchers, and this class has two methods, one is forward, the other is include, corresponding to implement dispatch in the JSP tag also has two:< Jsp:forward/> and <jsp:include/>.   whether it is forward or include, we can see clearly, from a servlet or JSP to a servlet or JSP jump, request and reponse always pass in the period, This is the key to the server-side implementation of the dispatch model. In other words, we can think of request and reponse as a resource, and a series of servlets and JSPs are calculated based on the same resource to fulfill their responsibilities.

The difference between the two is:

Redirection is the client behavior, and forwarding is the server behavior.

REDIRECT process: The client browser sends an HTTP request--"The Web server accepts a 302 status code response and corresponds to a new location to the client's browser--" The client browser finds that the 302 response, then automatically sends a new HTTP request, The request URL is the new location address-the server looks for resources based on this request and sends them to the customer. Here the location can be redirected to any URL, since the browser has re-issued the request, there is no concept of request delivery. The client browser path bar displays its redirected path, and the customer can observe the change of address. The redirect behavior is that the browser has made at least two access requests.

Forwarding process: The client browser sends an HTTP request-the Web server accepts this request-a method inside the container to complete the request processing and forwarding actions within the containers-the target resource is sent to the customer; here, the forwarded path must be a URL under the same Web container. It cannot be turned to other web paths, and the middle passes through the request within its own container. In the customer browser path bar is still the path of its first access, that is, the customer does not feel that the server is forwarded. The forwarding behavior is that the browser makes only one access request.


category concept shared data apply
redirect url Redirect: Can be any URL generally used to return to the main page and jump to other websites when the user logs off and so on
Forward Page forwarding: can only be another Web component of the same Web application Forwarded pages and forwarded pages can be in common with the data in request Typically used for user login to be forwarded to the appropriate module according to the role, etc.


From for notes (Wiz)

Redirection and forwarding in the Web

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.