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 07:20:02 -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=og4/Mm3Lr9xLrFb/eJzukyC6uX9HrpxdinmEPB5dBwxBVy7K154orQv+TXyzyvUStXOEY1kZOgJOnl7vVZEg6cYQJ0xOrDQNjlXNGZSOeqt1sXo+1EK6h/QjxOW4DpFM2t7kqFIGUWtrV8PDQ5/pXIxaHnqaFAsWOKsOTeFcOaY= ;
In-reply-to: <OF1AE6CE4E.29B2976D-ON85256F65.0052753B-85256F65.0052DB56@kroger.com>
Mailing-list: contact users-help@cinjug.org; run by ezmlm
DOH!  forgot about passing false!  Sorry about that.

-Jason


> Make sure you use request.getSession(false) or it
> will create a new one.
> 
> You could also do this:
> session = request.getSession()
> boolean isNewSession = false;
> if (session.isNew())  {
>       isNewSession = true;
> }
> 
> 
> Bill Manuel
> Sun Certified Web Component Developer
> bill.manuel@xxxxxxxxxx
> 
> 
> 
>                                                     
>                   
>              Jason Kretzer                          
>                   
>              <jrkretzer@yahoo.                      
>                 
>              com>                                   
>                    To
>                                       
> users@xxxxxxxxxx              
>              12/09/2004 09:56                       
>                    cc
>              AM                                     
>                   
>                                                     
>               Subject
>                                        Re:
> [cinjug-users] how to test if a
>              Please respond to         session is
> valid                
>              users@xxxxxxxxxx                       
>                 
>                                                     
>                   
>                                                     
>                   
>                                                     
>                   
>                                                     
>                   
>                                                     
>                   
> 
> 
> 
> 
> 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
> 
> ---------
> 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
> 
> 
> 
> 
> 
> ---------
> 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
> 
=== message truncated ===



                
__________________________________ 
Do you Yahoo!? 
Meet the all-new My Yahoo! - Try it today! 
http://my.yahoo.com 
 


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