Sendredirect, include, and forward differences in Jsp/servlet

Source: Internet
Author: User

Sendredirect

Response.sendredirect ();

According to the logic, the server sends a status code, tells the browser to request a new address again, generally speaking, the browser will use all the parameters just requested again, so the session,request parameters can be obtained. Note: You cannot read with the contents of the Request.setattribute. Because it's not the same request. As shown in the figure

2 forward

(1) Inside the servlet

Request.getrequestdispatcher ("jsp2.jsp"). Forward (request, response);

(2) inside the JSP

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

This column more highlights: http://www.bianceng.cn/webkf/JSP/

The page will be the content of page 2, the address bar does not change. Use the content of Request.setattribute to work properly because it is a request forwarding. As shown in figure

3 include

(1) Inside the servlet

Request.getrequestdispatcher ("jsp2.jsp"). Include (request, response);

(2) inside the JSP

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

The page contains the contents of page 1 and page 2, and the address bar is unchanged.

Using Request.setattribute content, you can get it normally.

Related Article

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.