• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to check session.invalidate() result ?  RSS feed

 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i want to check if the session is invalidated or not after calling invalidate() on the session. The problem is that there are values stored in the session object and i can still access the values after calling the invalidate method. here is how i m checking the invalidation.
//////////////////////////////////
HttpSession session = request.getSession(false);
session.invalidate();
if(session!=null)
String value= session.getAttribute("msg","Values");
//////////////////////////////////
Any help will be very much appreciated.
Regards
Gul
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pervaiz,
From my understanding the method you are using will not work since though you have invalidated the session you have not lost or destroyed the reference of the session object and that is what you are checking.
I would personally do something like:

In the above I am assuming if a session exists, then so should the clientID in the session. If I call invalidate(), then session.getAttribute("clientID") will be null and I can do whatever I need to do.
hth
 
Faisal Khan
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not used the getId() method but I assume, if you are not sure at any given time which objects are in the session then you should be able to use the getId() and check if the id is still there. Like I said, I have not used it so can not really comment on it more.
 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from what i understand after i call the invalidate it should invalidate the session and unbind all the objects bound to that session, so even if the session is not null it should return me null for getAttribute method??
 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Faisal the getId part worked. One more thing, if in a page i want to just check if the Id exists and session is still valid, i m using
session= request.getSession(false);
session.getId();
for that line i m still getting a session Id even when the session does not exist from before.
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaBeans get destroyed likewise along other vars? may check a JavaBean in session if not exist eg the clientID below?


// may invalidate session and immediatelly follows the below check in one page ?

if ( session.getAttribute("clientID") != null ) {
// no session, may be send them to a login page
} else {
// send them to a home page...
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!