aspose file tools
The moose likes Servlets and the fly likes Listener to detect when session ends Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Listener to detect when session ends" Watch "Listener to detect when session ends" New topic
Author

Listener to detect when session ends

John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 171
I want to do url tracking using a filter. I want to build up a string of delimited servlet names and insert then into a database. the tables would then be deleted every so often.
What type or is there an example i can use of a listener that will trigger the insert when the user closes the browser, loggs out, or the session expires?

thanks in advance
john
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3032
    
    4

John Schretz wrote:...What type or is there an example i can use of a listener that will trigger the insert when the user closes the browser, loggs out, or the session expires?
thanks in advance
john


trigger when the user closes the browser? None. You may find some javascripts that can be used to make a new request to the server informing it that the browser is being closed.

trigger when the user logs out? Depends how you log out. If you invalidate a session when they log out then see below.

trigger when the session expires? Use an HttpSessionListener (API Link)


Steve
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Steve Luke wrote:
trigger when the user closes the browser? None. You may find some javascripts that can be used to make a new request to the server informing it that the browser is being closed.
Even then, this isn't going to be crossbrowser compatible as at least Opera doesn't support it. Even then though, I won't use it. What if the user disabled Javascript? It can never be as reliable as you could do at the server side. Implementing the HttpSessionListener is the right approach, yes.


Code depot of a Java EE / JSF developer | JSF / Eclipse / Tomcat kickoff tutorial | DAO kickoff tutorial | I ♥ Unicode
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Bauke Scholtz wrote:
Even then, this isn't going to be crossbrowser compatible as at least Opera doesn't support it. Even then though, I won't use it. What if the user disabled Javascript? It can never be as reliable as you could do at the server side. Implementing the HttpSessionListener is the right approach, yes.


But when its possible to get the information close enough, why not get it. Otherwise, Listener is there in place.

Moreover, JavaScript disabled is not really the case to consider, IMHO, if not there as a requirement exclusively.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56185
    
  13

Trying to detect when the browser closes is folly. As it cannot be done reliably, any suppositions based upon that is suspect.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 171
Sorry for the late response I have been really busy
Just wanted to say thank you and i will look into HttpSessionListener
I will post any results i come up with
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Listener to detect when session ends
 
Similar Threads
How to create user defined and customized call back method in core java?
Doubt in Listener?
Can i distinguish between log out or session timeout?
Session Activation/Passivation
getting the IP when the session is created