在ServletOutputStream中写入字节时断管 [英] Broken Pipe when writing bytes in ServletOutputStream

查看:2248
本文介绍了在ServletOutputStream中写入字节时断管的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行此代码时,

  ServletOutputStream out = response.getOutputStream(); 
out.write(bytes,0,bytes.length);
out.flush();
out.close();

我经常收到此异常,我无法弄清楚它为什么会发生。

 由以下原因引起:ClientAbortException:java.net.SocketException:org.apache.catalina.connector.OutputBuffer.realWriteBytes中的管道损坏
(OutputBuffer.java:358)
at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:354)
at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer) .java:381)
at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:370)
at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:89 )

我在JBoss 4.2.3和MySQL下的linux服务器上运行了一个web应用程序。 / p>

这是怎么造成的,如何解决?

解决方案

通常这是由于客户端断开连接。客户端可能已断开连接的原因有多种(超时,浏览器已关闭等)。此外,作为一般惯例,如果您没有打开流,则不要关闭。有关关闭流的更多信息,请访问我应该关闭servlet输出流吗?


While executing this code,

ServletOutputStream out = response.getOutputStream();
out.write(bytes, 0, bytes.length);
out.flush();  
out.close();  

I'm getting this exception frequently and I can't figure out why it's happening.

Caused by: ClientAbortException:  java.net.SocketException: Broken pipe
    at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:358)
    at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:354)
    at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:381)
    at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:370)
    at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:89)

I have a web app running in a linux server, under JBoss 4.2.3 and MySQL.

How is this caused and how can I solve it?

解决方案

Typically this is due to the client disconnecting. There are several reasons the client may have disconnected (timed out, browser was closed, etc). Also, as general practice, if you didn't open the stream then don't close. More on closing the stream here Should I close the servlet outputstream?.

这篇关于在ServletOutputStream中写入字节时断管的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆