Not sure about using SocketWriteException.  A less elegant approach might be
to put a javascript function in the page that is called when the window is
closed.  That JS function could call a servlet that you can write.  (This is
a bit OT though because it's really to do with HTML rather than tomcat).

For example:

<HTML>
<HEAD>
<script language="JavaScript">
function  tellTomcat()
{
dummy.src = "/myWebApp/NotifyClose?windowId=xyz123";    // xyz123 generated
by your servlet or JSP, make it unique for each served instance of this page
}
</script>
</HEAD>
<body onunload="tellTomcat();">
<p>Page content here</p>
<img name="dummy" src="invisible.gif" width="0" height="0"/>
</body>
</HTML>

As an alternative to using windowId above, your NotifyCLose servlet could
just read the session from the request object.

> -----Original Message-----
> From: Stephan Coboos [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday 20 October 2004 16:33
> To: [EMAIL PROTECTED]
> Subject: How to get a notfication if the user closes its browser?
> 
> 
> Hi,
> 
> I need to send a very very big set of data within a servlet 
> to the users 
> browser. But if the users canceles the transmission or closes its 
> browser I need to cancel writting the data to save resources. 
> But if the 
> user canceles the response during transmission I don't get a 
> SocketWriteException? I had tested this behaviour by 
> executing a endless 
> while loop:
> 
> while(true) {
> 
>     out.write("Foo");
> }
> 
> But if the the browser will be closed during receiving the output, 
> tomcat doesn't break the while loop. Why? I thougt at this 
> point tomcat 
> schould throw an exception? Why not?
> 
> How can I break writing the output if the user closes it 
> browser? Thank you!
> 
> Regards
> Stephan
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to