• Post Reply Bookmark Topic Watch Topic
  • New Topic

Session Management in JSP  RSS feed

 
Murli Prasad
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once we set the session using session.setAttribute(). Will it stay active for the duration of session timeout set in WEB.XML
(I use tomcat server).

How can the user manually logout and create a new session(before the session timeout). Do we have to use session.inactivate method.
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sessoin resides until it expires. If you want to inactive it manually call
session.invalidate() method.
 
Murli Prasad
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers Dilshan, I have got the problem solved.

I got my problem sorted using the two functions session.invalidate()
and request.getSession.isNew().

whenever the isNew() method returns false, the user is redirected to the homepage and if the user wants to forcefully logout, I have used the session.invalidate() method to do so.

Thanks Dilshan for your time.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with trusting the isNew propery is that any hits to JSPs or servlets that can cause a session to be started will cause isNew to give you an inaccurate reading.

I've found that it's more reliable to to test to test for the existence of an object bound to session during a successful login. If the object is null, then you know the user is not logged in. If not then you know you have a valid session; and not one that was created two hits ago.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!