You can't since at the time that the listener is triggered you have no idea what's displayed in the user's browser or if they're even still looking at your site. Chances are they're long gone and browsing ebay or something...
The purpose of the listener is so that you can clean up after yourself if need be when the session times out.
If you want to detect that a session has timed out when a user hits one of your pages or controllers, that's a good job for a servlet filter.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Mar 31, 2006
Bear - could you please help me just a little bit more?
I've created the filter class you suggested and added it to web.xml - it gets called just fine, but I don't understand how to figure out if the session has timed out and then redirect (can I use RequestDispatcher?) to the sessionTimedOut.html page I want to display.
I do this by adding an object (userBean) to the session upon a sucessfull login. My filter checks for the existence of this object with each hit to the site. If the object doesn't exist in session (session.getAttribute("userBean" ) returns null) then I redirect the user back to the login screen.