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