Detecting client disconnect in tomcat servlet?

后端 未结 3 799
青春惊慌失措
青春惊慌失措 2020-11-28 14:08

How can I detect that the client side of a tomcat servlet request has disconnected? I\'ve read that I should do a response.getOutputStream().print(), then a response.getOutp

3条回答
  •  执念已碎
    2020-11-28 14:23

    is there a way I can detect this without writing any data?

    No because there isn't a way in TCP/IP to detect it without writing any data.

    Don't worry about it. Just complete the request actions and write the response. If the client has disappeared, that will cause an IOException: connection reset, which will be thrown into the servlet container. Nothing you have to do about that.

提交回复
热议问题