Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static Set value

 
Thirumalaisamy Thangavel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I have a static set and whenever a new user comes the name of that user will be added in that Set. When user clicks logout the name will be removed from the set.
But Instead of logout if the user closes the browser still the users name would be in the set.
So is there any way to remove the name from the Set when the user closes the browser or anyway way through AJAX.
Please give me a suggestion on this.

thiru
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Thirumalaisamy Thangavel:
hi,
I have a static set and whenever a new user comes the name of that user will be added in that Set. When user clicks logout the name will be removed from the set.
But Instead of logout if the user closes the browser still the users name would be in the set.
So is there any way to remove the name from the Set when the user closes the browser or anyway way through AJAX.
Please give me a suggestion on this.

thiru


You can fire a AJAX request on window.close event.(I do not know much about javascript , but i guess there is a similar event for tracking browser close.).If that is the case you can fire a ajax request to a servler.Which would remove the username from the set.One more thing is when you construct the ajax request , make a tag for sending the username.
On receiving the ajax request the servlet should fetch the username from the request and then remove that from the set.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These methods are not very reliable.
They won't work if the user's computer crashes or if their network connection is dropped.

A better approach is to set up a session listener that can remove the user's entry when their session is invalidated (either explictly from the user clicking the logout button or from a session timeout).
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
These methods are not very reliable.
They won't work if the user's computer crashes or if their network connection is dropped.

A better approach is to set up a session listener that can remove the user's entry when their session is invalidated (either explictly from the user clicking the logout button or from a session timeout).


Its true that these are not very reliable , but I think this is the only way for this issue.The initial post says that if the user clicks the close button on browser , not the logout of the application.


The session listner is again would not suite for this as , the this will have to wait for the session to timeout before it removes the element from the set.And if the session timeout for this application is a big value , then the element (that is the user name)would still be there in the set for that amount of time.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but the web is a stateless environment.
There is no reliable way to know if the user has left the page, closed the browser, experienced a PC crashm, or has lost network connectivity.

If it's important for these user objects to be removed from the set then a session listener is the best guarantee that they will be.
 
vishwanath nadimpally
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to use javascript, then you can use XMLHttpRequest object to fire a request on the window.close event. This is a wonderful page if you need more information on XMLHttp object :http://www.jibbering.com/2002/4/httprequest.html

but keep this in mind

Ben Souther
If it's important for these user objects to be removed from the set then a session listener is the best guarantee that they will be.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic