session| Tips
There were several questions about how to determine whether the session expired.
Contact with JSPO has been a long time, but really did not think about this problem, then did not find a satisfactory answer to the others.
At the time, I mentioned a way to implement the Httpsessionlistener interface and then do some action in the sessiondestroyed () method to indicate that the session is going to expire because this method is Session.invalidate () The method that the listener called before. This method of judgment is clearly not satisfactory.
I asked some people at the time, but I didn't get an accurate answer.
Just by chance, the Request.getseesion (Boolean) method suddenly dawned on me. This method has a Boolean value that, if true, creates a new session if the current session of the request is not available, and returns the current one if it exists. If the argument is false, NULL is returned when the current session of the request does not exist.
In this way we can easily associate this so-called request with the current session and the expiration of the link, so we can "approximately" think that the sessions do not exist is to expire, Then we can easily determine if the session is out of date. The method is as follows:
if (Request.getsession (false) ==null)
SYSTEM.OUT.PRINTLN ("Session has been invalidated!");
Else
System.out.println ("Session is active!");
It may be noted that I have an "approximate" word above, which means there is a special case.
This particular case is when the first request has not yet been created, and the return of this method is still null, and I think we should all be obvious.
The above is a personal humble opinion, I hope you will correct me.