Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Session Management in JSP

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic