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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
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: 188
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: 4181
    
  21

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.
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: 61224
    
  66

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
John Schretz
Ranch Hand

Joined: Sep 10, 2008
Posts: 188
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