Session inconsistency in JSP and Servlet

Source: Internet
Author: User

Today, when we were dealing with session variables, we were a little dizzy with a session problem.

The error is as follows: My local machine is running normally. When other machines on the LAN access my machine, select the first category and set a session with SID as "1, go to a page and retrieve "SID" from the session to get "1 ". Then, when I select the second category, set "SID" to "2", go to another page, and then retrieve "SID" from the session ", the obtained value is still "1 ".

I started printing in the background first, but when I selected the second category, the value of "SID" is still "1 ". It seems that when the page is from servlet to jsp (the first choice for SUN Enterprise applications), the session is still the first time and has not been updated. So I added a code to prevent IE from reading the cache:

Response. setHeader ("Cache-Control", "no-store ");
Response. setHeader ("Pragma", "no-cache ");
Response. setDateHeader ("Expires", 0 );

The problem was finally solved.

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.