After calling HttpSession.invalidate() method, what will be returned when we try to call getServletContext(), getMaxInactiveInterval() method which will not throw IllegalStateException exception like any other methods.
After calling HttpSession.invalidate() method,I called getServletContext(). There is no exception thrown. I tried to print context Object returned as well as session object before and after calling invalidate() method. It is printing correctly.
But is this the expected behavior. After the session is invalidated, how am I getting servletContext object instead of a null.
Thank you. Nice question. I got the answer too now. ServletContext is not only tied to a single client session. So, obviously it should not get effected when the session is invalidated. Similary getMaxInactiveInterval() will just give maximum inactive time a session can be. These two functions doesnot have anything to do with session validity or invalidiy.
Please correct me if I am wrong!!
But what about setMaxInactiveTime() which has to do with the current session which is already invalidated. I will test and revert back.
The method is getMaxInactiveInterval() but not getMaxInactiveTime().
After invalidaing method, I am still able to call set and get MaxInactiveInterval() method. I also observed that the changed maxInactiveInterval is updated on the invalidated session. Can any one tell me why?
Following is the code snippet I wrote in my servlet in which session object maxInactiveInterval is updated to 40mins even through it is invalidated. In the web.xml <session-timeout> is set to 30mins.
------------------------------------------
//code begins:
//code ended.
In the output it is showing that maxInactiveInterval is set to 40 mins.
Examining the API, I see that the methods which throw IllegalStateException are those which set or retrieve attributes. I suppose the developers didn't consider it necessary to throw an exception for other methods since there is no danger involved in using those methods on an invalid session.
Bill
Yes, of course, and I accept that blame. In fact, i covet that blame. As does this tiny ad: