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

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

问题描述

在执行这段代码时,

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

我经常收到此异常,但我不知道为什么会发生这种情况.

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

我有一个在 linux 服务器上运行的网络应用程序,在 JBoss 4.2.3 和 MySQL 下.

这是怎么引起的,我该如何解决?

解决方案

这通常是由于客户端断开连接.客户端断开连接的原因有多种(超时、浏览器关闭等).此外,作为一般做法,如果您没有打开流,则不要关闭.在此处详细了解关闭流我应该关闭 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天全站免登陆