Static variables and the use of the session

Source: Internet
Author: User

Recently, for a project, the data for a table needs to persist during the session. Because it's what someone else has done, it follows the original style of static variables to store the data :

public static list<word> words=wordrlist;

Later in the test found that with chrome and IE Open the project at the same time, the data will be overwritten, for example, Chrome passed in data a, and then IE passed in data b.

At this point , Chrome does nothing, just refresh, will find that the original data a into data b, that is, the static variable is the new data to be overwritten. Wouldn't it be a mess to use static variables for user variables?

This time should use the Session to replace the static variable: session["WordList"]=wodrlist;

Session is the server dedicated to the user variables of a mechanism, different users use the session is independent of each other, non-interference. Static variables are stored separately in the shared memory, that is, any user used static variable is actually the same, User B changed its value, User a before the value of the assignment is overwritten, see also User B assigned value.

All said that, in general web development, the user's personal data are stored in a cookie or session of this variable. Static variables are used for public data, such as the number of visits to a portal site or chats on a chat site.

Static variables and the use of the 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.