• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sessions

 
mamidi venkat
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
here i have doubt in session where session get expire/invalidate using the removeAttribute and invalidate().My Question is that this is only way to get session expire/Invalidate or anyway we can set in web.xml

session.removeAttribute("userBean");
session.invalidate();
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mamidi Venkat

See there are only two ways to invalidate a session.
Either the developer explicitly call invalidate() on session
or
the deployer can set <session-timeout> element under <session-config> in web.xml

One more thing, if you(developer) do session.setMaxInactiveTime(0) after creating session i.e. request.getSession(true), the session is invalidated or destroyed as soon as it's created.

And you don't have to call session.removeAttribute(String) to invalidate a session. As soon as a session is expired, all the data pertaining to that session is lost.

Yes, there is a method attributeRemoved(HttpSessionBindingEvent) in HttpSessionAttributeListener, which is called at the time of invalidation of session or when attribute is removed from the session.

Regards,
Khushhal
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mamidi,

Apart from what khushhal yadav has mentioned , I would like to add one more point that removeAttribute has got nothing to do with invalidating the session.

You can remove attribute that you have set in session before , only when you have a handle to a valid session object.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey...an Attribute is just a name value pair that you are adding to an already created scope (session/request/application/page) and it has got nothing to do with removing the scope itself out of scope. Hope you got it.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats right. Removing an attribute does NOT do anything for invalidating the scope (session).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic