简体   繁体   中英

HttpServletResponse : How to determine if the underlying connection is still open?

This is how it goes : A web based application running on Tomcat 6. A client sends a request to the server, server does some processing, makes a redirect to 3rd Party URL and again does some processing.

Before doing redirect, I want to know if the client connection is still open or not (so that I can prevent the second processing). I know sendRedirect throws IOException & IllegalStateException and those can be handled in case redirect fails.

I have also tried to obtain the output stream from response and write any junk characters to the stream. But to no use (even if I remove the client machine from the LAN, after invoking the request)

I want to know - is there any way I can identify if the connection between Client and Server is still active?

Old question but I was dealing with a similar problem and found a solution.

Aborted HTTP connection can indeed be detected only if the server sends something back to the client and that fails. To force sending the data to the client, you must call flushBuffer() on the HttpServletResponse. If the connection is aborted, this throws ClientAbortException .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM