According to the servlet spec, when calling
HttpServletRequest.getSession(boolean) with a parameter of false will tell
you if the session is valid:  "If create is false and the request has no
valid HttpSession, this method returns null."

So, one way of telling if a session is valid is:
HttpSession session = httpServletRequest.getSession(false);
if (session == null) {
        invalid session code...
}

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, February 13, 2002 10:14 AM
> To: Tomcat Users List
> Subject: Re: Redirect after session expires?
>
>
>
> There is no session.isInvalid() method - that wouldn't make any
> sense anyway.
> If you have an actual session to ask if it's valid or not, how
> could it ever
> be invalid?  There is an isNew() method, and I have not used
> this, but from
> reading the spec it doesn't sound like it will do the trick.
>
> There is a way to define an errorPage, a page that your JSP will
> forward to if
> it throws an Exception.  <%@ page errorPage="relativeURL" %>
> You'll have to
> put this in each of your pages though, so it might not be what
> you're looking
> for, although then all the logic to handle the exception would
> just be in the
> errorPage.
>
> You could also look into binding the session by creating an object that
> implements HttpSessionBindingListener.  Then when the session expires, the
> valueUnbound( event ) method will be called by the servlet
> engine.  You could
> put code in that method to handle this case.
>
> Hope this helps.
> -Jeff
>
>
>
>
>
>                     Michael
>
>                     Molloy               To:     "Tomcat Users
> List" <[EMAIL PROTECTED]>
>                     <mmolloy@ncyc        cc:
>
>                     les.com>             Subject:     Re:
> Redirect after session expires?
>
>
>                     02/13/02
>
>                     09:54 AM
>
>                     Please
>
>                     respond to
>
>                     "Tomcat Users
>
>                     List"
>
>
>
>
>
>
>
>
>
> Well, we're trying to keep as much logic out of the jsps as
> possible, so if
> there is a setting for web.xml or something to foward all pages that throw
> exceptions to a certain url, that's what I'm looking for.
>
> I appreciate your suggestion, and if that's what we need to do,
> we'll do it,
> but I'd like to know about any other possibilities, also.
>
> Thanks
> --Michael
>
> On Wed, 13 Feb 2002 15:37:53 +0000
> David Cassidy <[EMAIL PROTECTED]> wrote:
>
> > is there a session.isInvalid() method ?
> >
> > If so ... :)
> >
> > D
> >
> >
> >
> > Michael Molloy wrote:
> >
> > > I've got an application that builds menus when a user logs in
> and sticks
> the menus in an object which I then put inside the session. All subsequent
> jsps get their menu from that object in the session.
> > >
> > > However, when their session expires and they try to access a
> jsp, they get
> a NullPointerException, as expected.
> > >
> > > How can I catch that error and redirect them to the logon page? Or is
> their some other way to handle it? Is there a better way than
> putting some if
> else statements in the jsp to check the session for the menu object?
> > >
> > > Thanks
> > > --Michael
> > >
> > > --
> > > To unsubscribe:   <mailto:[EMAIL PROTECTED]>
> > > For additional commands: <mailto:[EMAIL PROTECTED]>
> > > Troubles with the list: <mailto:[EMAIL PROTECTED]>
> >
> >
> > --
> > To unsubscribe:   <mailto:[EMAIL PROTECTED]>
> > For additional commands: <mailto:[EMAIL PROTECTED]>
> > Troubles with the list: <mailto:[EMAIL PROTECTED]>
>
> --
> To unsubscribe:   <mailto:[EMAIL PROTECTED]>
> For additional commands: <mailto:[EMAIL PROTECTED]>
> Troubles with the list: <mailto:[EMAIL PROTECTED]>
>
>
>
>
>
>
> --
> To unsubscribe:   <mailto:[EMAIL PROTECTED]>
> For additional commands: <mailto:[EMAIL PROTECTED]>
> Troubles with the list: <mailto:[EMAIL PROTECTED]>
>
>


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to