Differences between sendRedirect, include and forward in jsp/servlet

Source: Internet
Author: User

1 sendRedirect

Response. sendRedirect ();

The server sends a status code based on the logic, telling the browser to request a new address. Generally, the browser will use all the parameters in the previous request to request a new address. Therefore, the session and request parameters can be obtained. Note: The content of request. setAttribute cannot be read. Because it is not the same request.

 

Request. getRequestDispatcher ("jsp2.jsp"). forward (request, response );

(2) In jsp

<Jsp: forward page = "include. jsp"/>

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 because it is request forwarding.

Request. getRequestDispatcher ("jsp2.jsp"). include (request, response );

(2) In jsp

<Jsp: include page = "include. jsp"/>

◆ The page will contain the content of page 1 and page 2 at the same time, and the address bar will remain unchanged.

◆ The content of request. setAttribute can be obtained and used normally.

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.