Pagecontext,request,session,application life cycle

Source: Internet
Author: User
Tags ranges

Equest is an object that encapsulates the request data and properties submitted by the client side (that is, by the user through browser).
Response is an object that encapsulates Web server-side response data and properties.


We often confuse PageContext, request, session, and application because they can both set or read properties through SetAttribute () and getattribute (). But there is something else between them, and their biggest difference is the scope of use.

The scope of the PageContext object applies only to the current page range, which means that more than this page can be used. Therefore, it is not possible to use the PageContext object to pass parameters to other pages.

The scope of the request object is when a JSP Web page makes a request to another JSP Web page, and then this property is invalidated.

The session is scoped to the length of time a user continues to connect to the server, but this property is invalid when disconnected from the server. such as breaking the net or closing the browser.

The scope of the application executes the service at the beginning of the server, until the server shuts down. It has the largest range and the longest life cycle.

Session Main function: Verify whether the user is logged in. Can be obtained on several pages.
Request: Only <jsp:forward page= "" > Jump page can be obtained.
Application: Once set, all page windows can get the data.
Application session request-> All need to span multiple pages
Setting too many application or saving too many objects per session degrades performance
If you can use the request, do not use the session can use the session do not use application

Application application: Online personnel statistics, online personnel list
PageContext: The Save scope of a page by default
In fact, four attribute ranges are done through the PageContext property.
Pagecontext.setattribute ("name", "Mldn", Pagecontext.request _scope), change the name of the Scarlet Letter to get.
On another page, use request to receive string Name= (string) request.getattribute ("name");<%=name%>;
To restart the server if you want to free application resources
The four attribute ranges are based on PageContext, but in development, the session and request range are often used.

Pagecontext,request,session,application 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.