users
[Top] [All Lists]

how to test if a session is valid

To: users@xxxxxxxxxx
Subject: how to test if a session is valid
From: "radha ganapathy" <radha_ganapathy@xxxxxxxxxxx>
Date: Wed, 08 Dec 2004 18:05:28 -0500
Bcc:
Delivered-to: mailing list users@cinjug.org
Mailing-list: contact users-help@cinjug.org; run by ezmlm
Hi,
I have an application deployed as ear file on weblogic6.1. The app has a class implementing HttpSessionAttributesListener.
On successful login, I use setMaxInactiveInterval to set the timeout to 5 minutes.
I use setAttribute to put the user id in the session with a tag of 'userid'.


In the doPost() of all my servlets, I have the following code to check if session is valid. but even if i leave my session inactive for more than 5 minutes, this function returns true because the attributer 'userid' is still there.

What is wrong in this method?

protected boolean isSessionValid(HttpServletRequest req)
{
HttpSession oSession = req.getSession();
System.out.println("oSession.getMaxInactiveInterval() : " + oSession.getMaxInactiveInterval());
System.out.println("oSession.getLastAccessedTime() : " + oSession.getLastAccessedTime());
String strUserID = (String)oSession.getAttribute("userid");
System.out.println("oSession.getAttribute(\"userid\"): " + strUserID);
if ( (strUserID == null) || (strUserID.length() == 0) ) {
return false;
} else {
return true;
}
}



Here is sample output from the print statements in that method : oSession.getMaxInactiveInterval() : 300 oSession.getLastAccessedTime() : 1102540440997 oSession.getAttribute("userid"): test123 oSession.getMaxInactiveInterval() : 300 oSession.getLastAccessedTime() : 1102544848815 oSession.getAttribute("userid"): test123

thanx,
radha.



<Prev in Thread] Current Thread [Next in Thread>