Rade Koncar wrote:If servlet is doing some lengthy operation before it writes to response object, and client has the time to close the browser,
what happens when data is finally being written to response object?
It goes into a black hole, never to be heard from again. Actually, I don't know where it goes, but it just goes away. Probably the allocated buffer is freed and garbaged collected. I never had any reason to investigate further.
Rade Koncar wrote:Is this the same situation as when user clicks Stop button?
No, not at all. If the user clicks a Stop button on a webpage, that usually just sends a new POST command with "stop"
This requires processing by whatever code is programmed to handle that command. So the exact details depend on what the programmer decided to engineer.
Rade Koncar wrote:Can servlet somehow detect that user terminated the connection?
Not quickly enough to do anything useful.
This is all fundamentally defined by the HTTP protocols. With HTTP, the client (browser) must initiate every action. The server is limited to responding to the request, once. The server (or servlet) can not initiate any actions outside the response to the client request. (It can, of course, if it wants, do anything in response to a client request, including talking to another thread, another server, etc.)
Joined: Sep 14, 2012
I tried writing this kind of servlet and deployed it in tomcat 6.0.36.
Indeed nothing happened. Then I checked if it generates some kind of exception that is silently caught by the container,
but nothing is being caught inside servlet.
I guess only way to detect it is to generate some kind of timeout exception when there is no communication on a TCP level for a long time...