简体   繁体   English

HttpServletResponse:如何确定基础连接是否仍处于打开状态?

[英]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. 它是这样的:在Tomcat 6上运行的基于Web的应用程序。客户端向服务器发送请求,服务器进行一些处理,重定向到第三方URL,然后再次进行一些处理。

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. 我知道sendRedirect会引发IOException和IllegalStateException,并且可以在重定向失败的情况下进行处理。

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. 仅当服务器将某些内容发送回客户端并且失败时,才可以检测到异常终止的HTTP连接。 To force sending the data to the client, you must call flushBuffer() on the HttpServletResponse. 要强制将数据发送到客户端,必须在HttpServletResponse上调用flushBuffer() If the connection is aborted, this throws ClientAbortException . 如果连接异常终止,则抛出ClientAbortException

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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