This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes perform a specific task on logout/closing of browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "perform a specific task on logout/closing of browser" Watch "perform a specific task on logout/closing of browser" New topic
Author

perform a specific task on logout/closing of browser

Kavita Ghia
Ranch Hand

Joined: Oct 10, 2000
Posts: 91
Hi,
I want to run a specific(rename the files that he has accesed on my server)action at both the instances -- either the user logs out or he/she shuts down the browser directly without loggingout.Its no problem whenever the user logs out properly bcoz that time i can run my servlet.However what if the user does not logout and closes the browser directly.
Any suggestions as to when should i run the servlet --
One solution i can think of is i can run the servlet maybe after every 20 mins.But then if i use this method then how do i invoke it every 20 mins.I am using Tomcat v 3.2.
1.Also is it an optimal solution???
2.Will it not increase load on the server-----Renaming few files every 20 mins.???

Is there any better alternative???

Plz. reply ASAP.
Thanking in advance,
Kavita
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

There's no guaranteed way to catch the closing of a browser -- you can create a javaScript call for onClose() (I think that's the command) -- but what if the user's browser doesn't support JavaScript? or what if they've disabled JavaScript?
I'm not familiar enough with TomCat to know if its possible to run a servlet every X minutes.


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15961
    
  19

That's about the most commonly asked question in this forum - click on "search" and see what others have said.
As far as running a servlet on a timed basis, that's not to be expected on ANY platform. Servlets are run in response to HTTP requests. You can have a task send an HTTP request periodically, but without receiving an HTTP request, a servlet doesn't run (startup code doesn't count).
The idea of trying to do something when a user "exits the application" just doesn't work on a web server. Aside from the fundamental architectural differences, web clients often "exit" by crashing (TOO often ). Try getting an event from THAT!
This is why modern servlet/JSP servers have support for session timeouts.


Customer surveys are for companies who didn't pay proper attention to begin with.
Robert Gagliardo
Greenhorn

Joined: Nov 15, 2001
Posts: 24
Use the HttpSessionBindingListener.
Stephen Wei
Ranch Hand

Joined: Oct 09, 2001
Posts: 73
Hi, I am assuming user use IE browser which supports Javascript. I want my LogoutServlet to run when the user pushes the logout button or close the browser. Here is my code, but my servlet will not get executed, my browser closes ok(I want the browser to close when the user logout), why is this? When I remove the "window.close();" line, my servlet will execute, is it because my window closes too quickly before it submits the form?

<script language = "javascript">
function logOut()
{
window.event.returnValue = false;
if(confirm("logout?")){
window.event.returnValue = true;
window.close();
}
}
</script>
<p align="center"><input type="submit" value="logout" action="http/myhost/LogoutServlet"
"onclick"="logOut()"></p>

Also, can someone explain the "onclose()" function to me? How do I submit a request to the servlet using only Javascript? something like:
Window.onclose(){
Document.myform.submit();
} /
???
Thanks!


Sun Certified Programmer for Java Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: perform a specific task on logout/closing of browser
 
Similar Threads
Stopping unauthorized access of files on the server
How to check browser alive
Browser Closing without signout from site
How to Execute Session Destroying code in jsp
Closing/Clearing objects within a Session when browser closes