Differences between sendredirect, include, and forward

Source: Internet
Author: User
Original article: http://blog.csdn.net/java2000_net/article/details/3002763


1. sendredirect
 

Usage:
The servlet is the same as the JSP.
  1. Response. sendredirect ();
Note:
The server sends a status code based on the logic, telling the browser to request the specified address again. Generally, you will put the required parameters in the forwarded address.
Note: The content using request. setattribute cannot be read. You can use session instead, or include or forward instead.

Flowchart

Ii. Include 

Usage
Servlet
  1. Request. getrequestdispatcher ("jsp2.jsp"). Include (request, response );
Inside JSP
  1. <JSP: Include page = "include. jsp"/>
Description
The page contains the content of page 1 and page 2 at the same time, and the address bar remains unchanged.
The content of request. setattribute can be used normally.

Flowchart




Iii. Forward 

Usage
Servlet
  1. Request. getrequestdispatcher ("jsp2.jsp"). Forward (request, response );
Inside JSP
  1. <JSP: Forward page = "include. jsp"/>
Description
The page will be the content of page 2, and the address bar will not change

The content of request. setattribute can be used normally.


Flowchart





Special tips

The include () method is used to forward requests to other servlets. The called Servlet's response to this request will be incorporated into the original response object, the original servlet can still output the response information. The forward () method is used to forward the request to other Servlets, And the called servlet is responsible for responding to the request, the execution of the servlet is terminated.

After include and sendrediect, the subsequent statements will continue to be executed, so return should be written in the appropriate position; Forward won't

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.