This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See welcome thread
Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Removing Users Sessions On Server ?  RSS feed

Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all the help with my previous question about adding users to an Arraylist.
Have now come up with an annoying problem with regards trying to remove them again
Basically, I have a jsp page that creates a simple user bean and then adds that bean to an arraylist. This arraylist when viewed on a seperate jsp page shows all the logged in users.
I've created a simple 'logout' page that will remove that user bean from the arraylist when they access it but I just can't seem to find a way of automatically removing sessions if the user just closes the browser window.
I'm using JRun to develop the application locally on my PC and have tried setting all thw various session timeout settings to one minute but still the arraylist keeps the user bean in there. My understanding is that if a session times out then any references to that object will become nulled out, however I just can't seem to get this to work.
I am running an applet on the workstation so initially I was using the destroy() method on here to try and call a servlet that would remove the relevant bean from the arraylist but I ran into problems trying to get the servlet to access the arraylist bean holding the list of users, maybe there is a way round this though ?
My knowledge of javabeans is pretty limited so I am using them only in their very simplest form.
Any ideas as to how I go about this or what I am doing wrong would be very gratefully received
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are going to have to catch the event that occurs when the session is invalidated and use that to remove the bean from the arraylist. The servlet engine does not know about your arraylist so it can't possibly reach into your servlet code and meddle with the reference in the arraylist.
Look at the various session listeners in the servlet API for what you want.
There have been a NUMBER of discussions of this problem on these forums in the past.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!