You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jacob Lauemøller <ja...@email.dk> on 2005/06/09 11:09:59 UTC

How to detect session close

Hi all,

Can I somehow detect that the current session is being closed without 
resorting to using a HTTPSessionListener directly?

Regards,
Jacob

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: How to detect session close

Posted by Jacob Lauemøller <ja...@email.dk>.
Thanks; well the effect I'm looking for is that the app stores some user 
preferences kept in the visit object in the database when the session closes 
e.g. because the user explicitly logs out or because the session times out.

I was hoping for an easy way to listen for session events. 

Anyway this may not be the right solution as it would allow situations where 
the user (a) closes the browser without logging out (so the session is still 
there until it times out and the preferences have not been saved yet) and (b) 
comes back and logs in again seeing his or her old preferences ... and so on.

On Thursday 09 June 2005 14:56, Bryan Lewis wrote:
> >From all I've heard, that's the only reliable way to detect that a session
>
> has timed out.  It's an asynchronous event outside your app's control.
>
> You could check for a valid session by looking for some known object in the
> visit, for instance the user object.  If you did that in some base-class
> method that gets called frequently enough (getPage() or getUser()), you
> might be able to detect a closed session before it caused any surprises for
> your pages.  My Visit.getUser() method throws a StaleSessionException if
> user == null, to avoid null-user checks throughout my page code.  It works
> but it's a bit messy and I'm not sure it's saved me that much effort... for
> example, I have to be careful not to call getUser() when I merely want to
> check whether the user is logged in without the side effect.
>
> If you're trying to avoid adding such plumbing code to your app, you could
> do it with an external servlet filter.  This site
> http://www.jspbook.com/code.jsp has code for a dead-simple filter
> (ConcurentUserTracker) that counts sessions. However, this would make it
> harder for your app to act upon the session closing.  Depends on what you
> want to achieve.
>
>
> ----- Original Message -----
> From: "Jacob Lauemøller" <ja...@email.dk>
> To: "'Tapestry users'" <ta...@jakarta.apache.org>
> Sent: Thursday, June 09, 2005 5:09 AM
> Subject: How to detect session close
>
> > Hi all,
> >
> > Can I somehow detect that the current session is being closed without
> > resorting to using a HTTPSessionListener directly?
> >
> > Regards,
> > Jacob
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: How to detect session close

Posted by Bryan Lewis <br...@maine.rr.com>.
>From all I've heard, that's the only reliable way to detect that a session
has timed out.  It's an asynchronous event outside your app's control.

You could check for a valid session by looking for some known object in the
visit, for instance the user object.  If you did that in some base-class
method that gets called frequently enough (getPage() or getUser()), you
might be able to detect a closed session before it caused any surprises for
your pages.  My Visit.getUser() method throws a StaleSessionException if
user == null, to avoid null-user checks throughout my page code.  It works
but it's a bit messy and I'm not sure it's saved me that much effort... for
example, I have to be careful not to call getUser() when I merely want to
check whether the user is logged in without the side effect.

If you're trying to avoid adding such plumbing code to your app, you could
do it with an external servlet filter.  This site
http://www.jspbook.com/code.jsp has code for a dead-simple filter
(ConcurentUserTracker) that counts sessions. However, this would make it
harder for your app to act upon the session closing.  Depends on what you
want to achieve.


----- Original Message ----- 
From: "Jacob Lauemøller" <ja...@email.dk>
To: "'Tapestry users'" <ta...@jakarta.apache.org>
Sent: Thursday, June 09, 2005 5:09 AM
Subject: How to detect session close


> Hi all,
>
> Can I somehow detect that the current session is being closed without
> resorting to using a HTTPSessionListener directly?
>
> Regards,
> Jacob
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org