问题描述
正常来说在wwb.write();wwb.close();这两个时候页面会弹出一个下载的页面但是现在wwb.close();执行之后没有弹出下载页面并且页面会出现页面无法显示后台报出这个错误这个应该如何解决网上修改连接数什么的方法都试过了ClientAbortException:java.net.SocketException:Connectionresetbypeer:socketwriteerroratorg.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:358)atorg.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:354)atorg.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:381)atorg.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:370)atorg.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:89)atjxl.write.biff.MemoryDataOutput.writeData(MemoryDataOutput.java:107)atjxl.write.biff.CompoundFile.writeExcelData(CompoundFile.java:505)atjxl.write.biff.CompoundFile.write(CompoundFile.java:455)atjxl.write.biff.File.close(File.java:120)atjxl.write.biff.WritableWorkbookImpl.close(WritableWorkbookImpl.java:447)atcom.brainlong.psi.wanda.depot.depotmanage.ShowDepotManageForSGAction.exportShipmentItemListDetail(ShowDepotManageForSGAction.java:1748)atcom.brainlong.psi.wanda.depot.depotmanage.ShowDepotManageForSGAction.exportShipmentItemListDetail(ShowDepotManageForSGAction.java:496)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atorg.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)atorg.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)atcom.brainlong.framework.struts.BaseDispatchAction.execute(BaseDispatchAction.java:97)atorg.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)atorg.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)atorg.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)atorg.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)atorg.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:617)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atcom.brainlong.psi.global.filter.LoginFilter.doFilter(LoginFilter.java:71)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atcom.brainlong.framework.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:39)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)atorg.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)atorg.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)atjava.lang.Thread.run(Thread.java:662)Causedby:java.net.SocketException:Connectionresetbypeer:socketwriteerroratjava.net.SocketOutputStream.socketWrite0(NativeMethod)atjava.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)atjava.net.SocketOutputStream.write(SocketOutputStream.java:136)atorg.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:740)atorg.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:434)atorg.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:349)atorg.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:764)atorg.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:126)atorg.apache.coyote.http11.InternalOutputBuffer.doWrite(InternalOutputBuffer.java:573)atorg.apache.coyote.Response.doWrite(Response.java:560)atorg.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:353)...43moreWritableWorkbookwwb=null;try{OutputStreamos=response.getOutputStream();//创建Excel工作表wwb=Workbook.createWorkbook(os);//创建sheetWritableSheetws=wwb.createSheet("出入库单据详情",0);//合并单元格(左列,左行,右列,右行)从第1行第1列到第2行第4列ws.mergeCells(0,0,17,1);Labelheader=newLabel(0,0,"出入库单据详情",ExportUtils.getHeader());ws.addCell(header);ws.mergeCells(0,2,17,2);Labell=newLabel(0,2,"导出时间:"+DateUtils.formatCurrentDate(DateUtils.DATE_PATTERN_YYYYMMDDHHmmss_2),ExportUtils.getTitle());//第3列ws.addCell(l);intk=0;l=newLabel(k++,3,"供货商名称",ExportUtils.getTitle());//第3行,第2列ws.addCell(l);......intres=0;ws.setColumnView(res++,30);ws.setColumnView(res++,15);//隐藏ws.setColumnView(res++,15);//隐藏......for(inti=0;i<list.size();i++){inth=0;ShipmentItemValueshipmentItemValue=list.get(i);if(shipmentItemValue!=null){l=newLabel(h++,i+4,shipmentItemValue.getSupplierName(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getOutStore(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getOutFacility(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getInStore(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getInFacility(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getShipmentTypeName(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);//l=newLabel(h++,i+4,shipmentItemValue.getShipmentId().toString(),ExportUtils.getNormolCell());//第2行,第6列l=newLabel(h++,i+4,shipmentItemValue.getSerialNumber().toString(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getDocumentDate().toString(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getEstimatedShipDate().toString(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getProductCategoryCode(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getProductCategoryName(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getProductCode(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getProductName(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,null==shipmentItemValue.getSpecification()?"":shipmentItemValue.getSpecification(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getUomTypeName(),ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getQuantity().setScale(6,BigDecimal.ROUND_HALF_UP)+"",ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getUnitPrice().setScale(6,BigDecimal.ROUND_HALF_UP)+"",ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);l=newLabel(h++,i+4,shipmentItemValue.getAmount().setScale(6,BigDecimal.ROUND_HALF_UP)+"",ExportUtils.getNormolCell());//第2行,第6列ws.addCell(l);}}wwb.write();wwb.close();os.flush();os.close();}catch(Exceptione){e.printStackTrace();}
解决方案
解决方案二:
wwb.write();wwb.close();os.flush();os.close();
建议把close写在finally块里。而且你的顺序似乎也有问题,wwb在osflush之前就关掉了。。。
解决方案三:
一开始报错的原因找到了是因为导出过程中有点了一次导出按钮冲突造成的但是那个显示无法找到页面的原因还是存在就是代码执行到wwb.close();的时候不弹出下载页面
解决方案四:
一下午我也在解决这个问题,wwb.write();wwb.close();os.flush();os.close();事实证明wwb和os的先后顺序并不影响。我最初在j代码里直接写的window.location.href=“导出execl的执行路径”,如此是可以下载文件的,后来自己优化用ajax的JSON提交,开始抛出上述的错误,最终无奈又改了回去,不过有一个问题一直未解决,就是返回时的路径一直都报错(我用的是struts2的框架)。
解决方案五:
javaexcel导出不支持ajax提交的吧?貌似只能用location.href=
解决方案六:
不支持ajax提交,后台加上response.setContentType("application/vnd.ms-excel;charset=utf-8");
解决方案七:
wwb.write(os);os不关闭
解决方案八:
创建的work的时候读进来的应该是你的excel的模板,不应该是输出流,读取模板模板用输入流,最后wbb.write(out)