Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

perform a specific task on logout/closing of browser

 
Kavita Ghia
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18218
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Robert Gagliardo
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the HttpSessionBindingListener.
 
Stephen Wei
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic