aspose file tools*
The moose likes Servlets and the fly likes Static Set value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Static Set value" Watch "Static Set value" New topic
Author

Static Set value

Thirumalaisamy Thangavel
Greenhorn

Joined: Sep 29, 2006
Posts: 3
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

Joined: Nov 29, 2005
Posts: 2308
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.


Rahul Bhattacharjee
LinkedIn - Blog
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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).


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Jan 25, 2005
Posts: 116
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static Set value