Tips for judging whether a session has expired

Source: Internet
Author: User

There were several problems some time ago, and I mentioned how to determine whether the session has expired.
I have been in contact with jspo for a long time, but I have never thought about this question. At that time, I didn't find a satisfactory answer.
At that time, I mentioned a method to implement the httpsessionlistener interface, and then execute some operations in the sessiondestroyed () method, which indicates that the session will expire because the method is session. method called by the listener before invalidate. This judgment method is obviously not satisfactory.
I asked some people, but I didn't get an accurate answer.
I suddenly realized that the request. getseesion (Boolean) method. In this method, a Boolean value is passed. If this value is true, a new session is created if the current request session is unavailable. If yes, the current session is returned. If the parameter is false, null is returned if the current session of the request does not exist.
In this way, we can easily think of whether the current session of this so-called request has a connection with the session expiration, so we can "approximately" think that the session does not exist because the session has expired, then we can easily determine whether the session has expired. The method is as follows:
If (request. getsession (false) = NULL)
System. Out. println ("session has been invalidated! ");
Else
System. Out. println ("session is active! ");

You may have noticed that there is an "Approximate" word above, that is, there are special situations.
In this special case, when the first request has not yet created a session, the returned value is still null in this method. I think it should be clear to everyone.

I hope you can correct the above.

Http://www.moon-soft.com/doc/44994.htm

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.