• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Listener to detect when session ends

 
John Schretz
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to detect when the browser closes is folly. As it cannot be done reliably, any suppositions based upon that is suspect.
 
John Schretz
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic