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
|