• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

perform a specific task on logout/closing of browser

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 26275
186
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the HttpSessionBindingListener.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic