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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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.
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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__
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.