HttpServletRequest the difference between object request forwarding and HttpServletResponse object request redirection

Source: Internet
Author: User

The HttpServletRequest object request represents the browser requests object, the HttpServletResponse object represents the server response object, and when a browser accesses the Web server, the request is made. The servlet invokes the service method and passes in the two objects, and then forwards or redirects to the next JSP page or servlet via a request, following the difference between request forwarding and Response object request redirection:

The Requestdispatcher.forward method can only forward requests to components in the same Web application, while Httpservletresponse.sendredirect Methods can also be redirected to resources in other applications at the same site, even resources that are redirected to other sites by using an absolute URL.


The difference is that if the relative URL passed to the Httpservletresponse.sendredirect method begins with "/", it is relative to the root of the entire Web site, and if the relative URL specified when creating the RequestDispatcher object is "/" At the beginning, it is relative to the root directory of the current Web application.


Difference Three, After the access process that calls the Httpservletresponse.sendredirect method redirects, the URL displayed in the browser's address bar changes, and the initial URL address becomes the target URL of the redirect; Call Requestdispatcher.forward The browser address bar keeps the initial URL address intact after the request-forwarding process for the method is completed.


Difference Four, The Httpservletresponse.sendredirect method responds directly to the request of the browser, and the result of the response is to tell the browser to re-issue the access request to the other URL, and the Requestdispatcher.forward method forwards the request to another server-side A resource, the browser only knows that a request has been made and has received a response, and does not know that a forwarding behavior has occurred inside the server program.


Difference Five, The caller of the Requestdispatcher.forward method shares the same request object and the response object as the callee, which belong to the same access request and response process, while the Httpservletresponse.sendredirect method caller and the The caller uses the respective request object and the response object, which belong to two separate access request and response procedures.

HttpServletRequest the difference between object request forwarding and HttpServletResponse object request redirection

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.