• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSession.invalidate() method

 
kranthi adari
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Do they retrun null.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kranthi adari:
which will not throw IllegalStateException exception like any other methods.


getServletContext() . i dont think , it is difficult to test yourself
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This would be extremely easy to test. Please let us know what you discover.
[ January 01, 2009: Message edited by: Bear Bibeault ]
 
kranthi adari
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you think that the session would have any effect whatsoever on the servlet context?
 
kranthi adari
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
kranthi adari
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kranthi adari:
I also observed that the changed maxInactiveInterval is updated on the invalidated session


No,I tested . but dont find this behaviour.
 
kranthi adari
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic