A tip that judges if session expired

xiaoxiao2021-03-06  48

There are several problems before a period of time, mention how to judge whether the session has expired. It has been a long time, but I haven't thought about this issue, and I didn't find a satisfactory answer to others. At that time, I mentioned a method to implement the HTTPSessionListener interface, then execute some operations in the sessionDestroyed () method, indicating that the session is going to expire, because this method is the method called before the SESSION.INVALIDATE (). This method of judgment is obviously not satisfactory. I asked some people at the time, but I didn't get an accurate answer. Just occasionally see that the Request.GetSeesion (Boolean) method makes me suddenly realize. This method has passed a boolean value. This value is if it is true, then if the current Request's session is not available, then create a new session if there is a current session. If the parameter is false, then returns NULL when the current session of the request is not existed. This way we can easily Lenovo's current session of this so-called Request exists and the session expiration, so we can "approach" think that session does not existence, then we can easily judge the session Whether it has expired. The method is as follows: if (Request.GetSession (false) == null) System.out.Println ("session has been invalidate!"); Else System.out.println ("Session is Active!");

I may notice that I have a "approximation" word above, which means there is a special situation. This special situation is that when the first request has not created a session, then the use of this method is still null, the reason I think everyone should be obvious.

The above is personal, I hope everyone will correct it. Note:

Servers: jfresh_man (The Answer IS ...) (God said to me: Programming is comprehensive development,)

转载请注明原文地址:https://www.9cbs.com/read-53869.html

New Post(0)