linux环境tomcat服务器导出excel报错java.net.SocketException: Broken pipe

酱酱鹏 2015-08-05 11:42:18
在windows环境导出excel没有什么问题,到了linux环境报错
错误情况如下
2015-08-05 11:40:56,268 WARN [com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor] (http-bio-18095-exec-8) java.net.SocketException: Broken pipe
org.apache.catalina.connector.ClientAbortException: java.net.SocketException: Broken pipe
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:407)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:480)
at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:356)
at org.apache.catalina.connector.OutputBuffer.close(OutputBuffer.java:308)
at org.apache.catalina.connector.CoyoteOutputStream.close(CoyoteOutputStream.java:108)
at org.apache.struts2.dispatcher.StreamResult.doExecute(StreamResult.java:274)
at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:361)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265)
at com.cost168.framework.web.SubSiteInterceptor.intercept(SubSiteInterceptor.java:79)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.cost168.framework.web.XssFilter.doFilter(XssFilter.java:31)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:215)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:480)
at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:366)
at org.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:240)
at org.apache.coyote.http11.filters.IdentityOutputFilter.doWrite(IdentityOutputFilter.java:93)
at org.apache.coyote.http11.AbstractOutputBuffer.doWrite(AbstractOutputBuffer.java:192)
at org.apache.coyote.Response.doWrite(Response.java:499)
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:402)
... 57 more

WritableWorkbook wwb = null;
OutputStream os = null;
HttpServletResponse response = contextPvd.getResponse();
try {
response.reset();
response.setHeader("Content-disposition",
"attachment; filename="
+ new String(standardMap.get("STANDARD_NAME").toString().getBytes("GBK"), "ISO_8859_1")
+ ".xls");
response.setContentType("application/msexcel");
os = response.getOutputStream();
// 根据传进来的file对象创建可写入的Excel工作薄
wwb = Workbook.createWorkbook(os);
/*
* 创建一个工作表、sheetName为工作表的名称、"0"为第一个工作表 打开Excel的时候会看到左下角默认有3个sheet、"sheet1、sheet2、sheet3"这样
* 代码中的"0"就是sheet1、其它的一一对应。 createSheet(sheetName, 0)一个是工作表的名称,另一个是工作表在工作薄中的位置
*/
WritableSheet ws = wwb.createSheet(standardMap.get("STANDARD_NAME") + "", 0);

// 创建单元格样式
WritableCellFormat wcf = new WritableCellFormat();
WritableFont font1 = new WritableFont(WritableFont.TIMES, 12, WritableFont.BOLD);
// 背景颜色设置为"那什么"色
wcf.setFont(font1);
/*
* 这个是单元格内容居中显示 还有很多很多样式
*/
wcf.setAlignment(Alignment.CENTRE);

// 判断一下表头数组是否有数据
if (columns != null && columns.length > 0) {
// 循环写入表头
for (int i = 0; i < columns.length; i++) {
/*
* 添加单元格(Cell)内容addCell() 添加Label对象Label() 数据的类型有很多种、在这里你需要什么类型就导入什么类型 如:jxl.write.DateTime
* 、jxl.write.Number、jxl.write.Label Label(i, 0, columns[i], wcf) 其中i为列、0为行、columns[i]为数据、wcf为样式
* 合起来就是说将columns[i]添加到第一行(行、列下标都是从0开始)第i列、样式为什么"色"内容居中
*/
ws.addCell(new Label(i, 0, columns[i], wcf));
}
if (list != null && !list.isEmpty()) {
for (int i = 0; i < list.size(); i++) {
Map<String, Object> map = list.get(i);
ws.addCell(new Label(0, i + 1, i + 1 + ""));
ws.addCell(new Label(1, i + 1, ObjectUtils.toString(map.get("MATERIAL_CODE"))));
ws.addCell(new Label(2, i + 1, ObjectUtils.toString(map.get("MATERIAL_NAME"))));
ws.addCell(new Label(3, i + 1, ObjectUtils.toString(map.get("MATERIAL_STANDARD"))));
ws.addCell(new Label(4, i + 1, ""));
ws.addCell(new Label(5, i + 1, ObjectUtils.toString(map.get("MATERIAL_UNITS"))));
ws.addCell(new Label(6, i + 1, ObjectUtils.toString(map.get("DEPLOY_PRICE"))));
ws.addCell(new Label(7, i + 1, ObjectUtils.toString(map.get("MAX_PRICE"))));
ws.addCell(new Label(8, i + 1, ObjectUtils.toString(map.get("MIN_PRICE"))));
ws.addCell(new Label(9, i + 1, ObjectUtils.toString(map.get("MEMO"))));
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
log.error(ex.getMessage());
} finally {
try {
wwb.write();
wwb.close();
os.close();
} catch (WriteException e) {
e.printStackTrace();
log.error(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage());
}
}

...全文
301 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
酱酱鹏 2015-08-05
各位大神,又碰到过类似问题的没有,提供下解决思路,不胜感激。
回复
Golden_Dog 2015-08-05
试试不要关闭response.getOutputStream(); 在tomcat中会关闭的
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-08-05 11:42
社区公告
暂无公告