The difference between Servlet Request forwarding and redirection ------ the difference between the two is illustrated by living instances

Source: Internet
Author: User

1. Request redirection: the client behavior, response. sendredirect (), is essentially equivalent to two requests. The previous request object will not be retained, and the URL address in the address bar will change.


2. Request forwarding: Server behavior. Request. getrequsetdispatcher (). Forward (requset, response) is a request. After forwarding, the request object will be saved and the URL in the address bar will not change. (Internal server forwarding. All clients cannot see the changes in the address bar)



The following is an example of life:

Request redirection: it is like finding an advertisement Company A to design a business card. Company A clearly tells us that they will not design it. Let's look for company B. As a result, Company B has designed it for me, so we will claim to be the business card designed by Company B for US (so we send two requests, from Company A to Company B in the URL address bar)


Request forwarding: I also went to Company A to design the business card. Although Company A could not design it, but they took over our work and outsourced the task to Company B, in the end, we will give the money to Company A and claim that Company A has designed the business card for us. This is request redirection (so we send only one request to Company, company A in the URL address bar ).

The difference between Servlet Request forwarding and redirection ------ the difference between the two is illustrated by living instances

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.