users
[Top] [All Lists]

Re: [cinjug-users] how to test if a session is valid

To: users@xxxxxxxxxx
Subject: Re: [cinjug-users] how to test if a session is valid
From: Jason Kretzer <jrkretzer@xxxxxxxxx>
Date: Thu, 9 Dec 2004 06:56:01 -0800 (PST)
Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Delivered-to: mailing list users@cinjug.org
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; b=B3SXkL3Ng3HfPlYZQS9unOFSME1h0YERhV3NZzOjzUH7thO3UcXepUAhT3Qh0ElH5Nk5SaFC8LT05UXeVsG1QbERfEYdhNawOr0kNWwakj/7SUfH70YtSRfoA8WRQvTuLsT9GaVFjgGl+JMRcOkM/rRnNTgiiO4p2VUxFiXOUM8= ;
In-reply-to: <BAY101-F11621850FA869D1560353693B60@phx.gbl>
Mailing-list: contact users-help@cinjug.org; run by ezmlm
Try this:

HttpSession oSession = req.getSession();
if(oSession == null)
{
    //this session has timed out.
}


-Jason

--- radha ganapathy <radha_ganapathy@xxxxxxxxxxx>
wrote:

> 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.
> 
> 
> 
> ---------
> You may unsubscribe from this mailing list
> by sending a blank email addressed to:
> users-unsubscribe@xxxxxxxxxx
> 
> --
> Find additional help by sending a blank email
> addressed to:
> users-help@xxxxxxxxxx
> 
> 



                
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250

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