Usage and differences of four domain objects, page, request, session, and Application

Source: Internet
Author: User

1. Page indicates the current page. Valid only for one JSP page.
2. Request refers to the whole process of returning a response from the HTTP request to the server processing end. In this process, the forward method is used to jump to multiple JSPs. You can use this variable on these pages.
3. The session is valid for the current session, which is closed from the browser to the browser.
4. Application it is effective for the entire application.
The variables in the scope have the longest survival time. If they are not manually deleted, they can always be used.
The variables in the page cannot be passed from index. jsp to test. jsp. As long as the page jumps, they will disappear.
The variables in the request can span the two pages before and after the forward. However, you only need to refresh the page, and they will recalculate it.
The variables in the session and application have been accumulating and there is no difference at first. As long as you close the browser and restart the browser to access this page, the variables in the session will be recalculated.
The variables in the application keep accumulating. Unless you restart tomcat, it will keep increasing.
The scope specifies the validity period of the variable.
If you put the variable in pagecontext, it indicates that its scope is page, and its valid range is only in the current JSP page.
You can use this variable from placing it in pagecontext to the end of the JSP page.
If you put the variable in the request, it indicates that its scope is request, and its valid range is the current request cycle.
The request cycle refers to the whole process from initiating an HTTP request to processing the server and returning a response. In this process, you may use the forward method to jump to multiple JSP pages. You can use this variable in these pages.
If the variable is put into the session, it indicates that its scope is session, and its valid range is the current session.
The current session refers to the process from when the user opens the browser to when the user closes the browser. This process may contain multiple request responses. That is to say, as long as the user is not in the browser, the server can know that these requests are initiated by a person. The whole process is called a session and put into the session variable, it can be used in all requests of the current session.
If you put the variable in the application, it indicates that its scope is application, and its effective scope is the entire application.
The entire application starts from the application and ends with the application. We didn't say "starting from the server to shutting down the server" because one server may deploy multiple applications. Of course, if you close the server, all the above applications will be shut down.
Variables in the application scope have the longest survival time. They can be used without manual deletion.
Different from the preceding three, the variables in the application can be shared by all users. If user a's operations modify the variables in the application, user B obtains the modified value during access. This will not happen in other scopes. pages, requests, and sessions are completely isolated, and data of others will not be affected no matter how modified.

The range of the pagecontext object is only applicable to the current page range. Therefore, it is impossible to pass parameters to other pages using the pagecontext object.
The scope of the request object refers to the failure of this attribute after a JSP page sends a request to another JSP page.
The range of a session is the duration of the user's connection to the server. However, this attribute is invalid when the session is disconnected from the server. For example, if the network is disconnected or the browser is closed.
The scope of the application is to run the service at the beginning of the server until the server is closed. It has the largest range and the longest life cycle.

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.