When processing a large amount of data in a JSP or Servlet, is there anyway to know that the user has either used the "Stop" button, or closed the window?

Serge Knystautas

Although JSPs/servlets shield you from the raw socket connection, you can test the outputstream to see if it is still usable and thereby determine whether the connection is still open. To test the outputstream, try the following snippet:

out.print(" ");

If the socket is closed (because the user has hit Stop or closed the window), the outputstream is closed and you will get an IOException.

Note that this test assumes you are returning HTML, which will ignore extra white space. If you are returning binary data such as a file, you cannot use this trick.