Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Variables - Valid and otherwise

 
George Larry
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to create a session for my web page that expires after 15-20 minutes- then, once expired, have the user forwarded to the login page.
I think I've got the timing thing down...
session.setMaxInactiveInterval( x );
The part I don't know how to do is check for the invalid session and do the forward. I haven't found any way to tell if the session.isInactive();
Here's what I'd like to do:

There is no isInactive() function... that I know of. How can this be done?
Thank you.
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can do like this..
if(session.getValue(" ")==null)
{
response.sendRedirect("logon.jsp");
}
Thanks
Pranit..
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternatively, you can use the standard authentication mechanism and set the sessions to timeout (at the application level) after X minutes. Users will then automatically be returned to the login page when they try to access a protected resource.
Simon
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or if you don't want to use the standard authentication mechanisn, you could use a filter (from Servlets 2.3) to wrap up this logic for you. This saves you putting it on every page.
Simon
 
George Larry
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm... I tried that, but I'm getting an IllegalStateException.
Here's what I've done (in my header.jsp file):

Any ideas?
 
George Larry
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the standard authentication mechanism and where can I learn how to use it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic