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

Posted on 2006-04-26
Last Modified: 2008-03-10
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?
Question by:toets
    LVL 5

    Expert Comment

    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.
    LVL 4

    Expert Comment

    //when close a window
    window.onbeforeunload =
        if((window.event.clientX<0) || (window.event.clientY<0)){
                  //do what ever u want here

    Author Comment

    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.
    LVL 8

    Accepted Solution

    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.


    Author Comment

    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.
    LVL 8

    Expert Comment

    As far as I can see, the use has implemented my last post, colr__

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    Can I clean log of  running tomcat 7 server ? 3 108
    java beans and EJBs 5 178
    lessBy10  challenge 15 84
    maven webservice example issue 2 61
    Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
    PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now