In a JSP page, how to know if user closed IE window or clicked Stop button when processing large amount of data?

We have a jsp page that each time it takes a couple of minutes to processing large amount of data. So we expect the server to stop processing when user closes the window, hits Esc key or clicks Stop button in IE so that the server won't be overloaded. It is a popup window though. So when user closes the window, the session has not expired and we cannot achieve this by checking session. The same page works fine in OC4J but not in Tomcat or Jboss. I tried to put code 'out.print(" "); out.flush();' and it does not work. What else can I do?
Who is Participating?
What about this -

Maintain a static list of the 'processes' as they are executing. So once the prcoess begins, it adds a reference to itself to this list, and when the process stops the process is removed from the list.

On the client side, use javascript to determine when the window is closed (there is no server side way of doing this). When the javascript detects a closed window, get it to post to a servlet with some sort of ID for identifying which process should be terminated on the server.  The servlet (which the javascript posts to) would then just stop the process (you'd have to write code to allow this to happen to your process) and remove it from the list of active processes.

If user clicks the stop or Esc button the request is aborted so you need not do any thing in that case.
For the case when user closes the window I don't think there is a way to know that because neither requested is aborted nor session got killed.
//when close a window
window.onbeforeunload =
    if((window.event.clientX<0) || (window.event.clientY<0)){
              //do what ever u want here
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

toetsAuthor Commented:
Well, the problem is that on server side, the process will continue until finish even after end user closes the window, clicks Stop, or hit Esc or F5 key (the session won't be killed cause it is a popup child window). So if user continue hit F5, it is going to crash server or makes server extremely slow. It is interesting that OC4J knows this kind of event but Tomcat does not. What I am looking if there is a server side solution.
toetsAuthor Commented:
I think I figured it out. I added code in jsp page to store a session attribute when a process starts and removes it when the process stops. Thus the user has to wait until the first one finishes to be able to request another one. If user requests to run the process again before the process finishes, jsp page will diplay error and won't kick off another process. Thanks for all comments though.
As far as I can see, the use has implemented my last post, colr__
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.