Exchanging data between JSP Servlets

Source: Internet
Author: User

Excerpt from: "Lightweight Java EE Enterprise Application" Third edition

For each client request, the Web server roughly needs to complete the following steps:

1. Start a separate thread

2. Use I/O stream to read the user's request parameters

3. Parsing parameters from the request data

4. Handling User Requests

5. Generate Response Data

6. Send request data using I/O flow to the client

1, 2, 6 is universal, by the Web server completed, 3, 4, 5 There are differences, because different requests contain the request parameters are different, the way the user requests are processed differently, the resulting response is different, this 3 step is done by the servlet's _jspservice () method. When writing a JSP page, the static content of the page, the JSP script will be converted to the _jspservice () method execution Code (note: JSP Java declaration, that is, <%! ...%> is a member variable and member method after the JSP is converted to a servlet, not in the _jspservice () method, which is responsible for parsing parameters, processing requests, generating responses, and so on, while the Web server completes the underlying functions of multithreading, network communication, and so on.

Exchanging data between JSP Servlets (personally feel that the servlet here should not be the servlet that was generated after the JSP was compiled)

Application Session Request page

Application: Valid for the entire Web application, once the JSP, Servlet puts the data into session, the data will be used by all other JSPs, servlet access

Session: Only valid for a single reply, once the JSP, servlet data into the session, the data will be all the other JSP, servlet access

Request: Valid only for this time, once the JSP, Servlet puts the data into request, the data will be accessed by other JSPs, servlet

Page: Valid only for the current page, once the JSP, Servlet puts the data into the page, the data can only be accessed by the JSP script, the declaration part of the current page

Sessions should typically only store information that is relevant to the user's session state. If you are simply exchanging information for two pages, you can store that information in the request and then forward it.

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.