简体   繁体   English

HttpServletResponse#sendError()是否会抛出IOException吗?

[英]Does HttpServletResponse#sendError() ever throw an IOException?

The doc explains that the HttpServletResponse#sendError() method throws an IOException if an input or output exception occurs ( DRY ;). 文档解释说, 如果发生输入或输出异常DRY ;),则HttpServletResponse#sendError()方法将引发IOException

I couldn't find any scenario that makes this method throw that exception, is there any? 我找不到使该方法抛出该异常的任何情况,有吗?

HTTP is sent over TCP so you can safely assume that somewhere in the underlying HttpServletRequest and HttpServletResponse there is a SocketInputStream and a SocketOutputStream . HTTP是通过TCP发送的,因此您可以放心地假设在基础HttpServletRequestHttpServletResponse中的某个位置有SocketInputStreamSocketOutputStream

If a user closes their browser or the network goes down client-side or server-side, then the server won't be able to receive requests or send responses. 如果用户关闭浏览器或网络在客户端或服务器端断开,则服务器将无法接收请求或发送响应。 If the disconnection happens while the server was in the process of sendError() , then an IOException will occur while writing to the SocketOutputStream . 如果断开连接是在服务器处于sendError()过程中发生的,则在写入SocketOutputStream将发生IOException。

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

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