The difference between application and session

Source: Internet
Author: User

1.session is a session variable, so long as the same browser is not closed, the session object will exist. So in the same browser window, no matter how many requests are sent to the server, there is only one session object. However, if the client does not make a request to the server for a long time in a session, the session object disappears automatically. This time depends on the server, but we can write a program to modify the session's life cycle time. Session.setmaxinactiveinterval (10000);//used to set the session is valid for 10,000 seconds, beyond which the range will expire.

and through the session object can store or read the customer's relevant information, such as user name or shopping information, can be through the Session object SetAttribute (String name,object obj) method and GetAttribute ( String name) of the method implementation. Note that the return value of the GetAttribute () method is the object type, and if you assign the obtained information to a variable of type string, you need to either force the type conversion or call its ToString () method.

Session.setattribute ("User", "nickname");
String user= (String) session.getattribute ("User");


2.application It is similar to a global variable of a system that holds public data in all programs. It is created automatically when the server is started and destroyed when the server is stopped. When the Application object is not destroyed, all users can enjoy the Application object. Its life cycle can be said to be the longest. However, the parameters of the application initialization are set in the Web. xml file, and the application initialization parameters are configured with the <context-param> tag. In other words, when you open another browser, they use the same Application object.

The difference between application and session

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.