• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

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?
0
toets
Asked:
toets
1 Solution
 
gksinghietCommented:
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.
0
 
aaaaaaCommented:
<script>
//when close a window
window.onbeforeunload =
  function(){
    if((window.event.clientX<0) || (window.event.clientY<0)){
              //do what ever u want here
    }
  }
</script>
0
 
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
colr__Commented:
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.

colr__
0
 
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.
0
 
colr__Commented:
As far as I can see, the use has implemented my last post, colr__
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now