This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Checking for valid session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Checking for valid session" Watch "Checking for valid session" New topic

Checking for valid session

ShivPrakash Srivastava
Ranch Hand

Joined: Mar 24, 2005
Posts: 88

Is there any method in HttpSession or in the request to check for session timeout?

Thanks and Regards
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
if request.getSession(false) is null , then session has timed out or never created.

Rahul Bhattacharjee
LinkedIn - Blog
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

The simplest way, I've found, is to bind an object to session when a user logs in. Then check to see if that object exists (is not null).

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
add a Session listener ?
ShivPrakash Srivastava
Ranch Hand

Joined: Mar 24, 2005
Posts: 88
Hi All,

Thanks to all of you for your response.

Thanks and Regards
I agree. Here's the link:
subject: Checking for valid session
Similar Threads
Alternative to Cookie?
Field set in action method coming null in JSP
Session problem in NetBeans
Advice on persisting complex state across multiple server trips