• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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.
 
I promise I will be the best, most loyal friend ever! All for this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic