文件下载取消保存下载异常

 Java代码 复制代码 收藏代码

  1. Caused by: java.net.SocketException: Connection reset by peer: socket write error
  2. at java.net.SocketOutputStream.socketWrite0(Native Method)
  3. at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
  4. at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
  5. at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:737)
  6. at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:434)
  7. at org.apache.coyote.http11.InternalOutputBuffer.flush(InternalOutputBuffer.java:299)
  8. at org.apache.coyote.http11.Http11Processor.action(Http11Processor.java:963)
  9. at org.apache.coyote.Response.action(Response.java:183)
  10. at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:314)
  11. ... 26 more
  12. 2012-12-14 9:22:13 org.apache.catalina.core.StandardWrapperValve invoke
  13. 严重: Servlet.service() for servlet action threw exception
  14. java.lang.IllegalStateException: Cannot forward after response has been committed
  15. at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:302)
  16. at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
  17. at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
  18. at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:398)
  19. at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241)
  20. at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
  21. at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
  22. at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
  23. at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
  24. ......................
  25.  
  26. 下载代码:
  27.  
  28. os = response.getOutputStream();
  29. is = new FileInputStream(new File("download.wmv"));
  30.  
  31. response.reset();
  32. String fileName = "download.wmv"
  33. response.setHeader("Content-disposition", "attachment;filename =" + new String(fileName.getBytes("GBK"),"ISO8859-1"));
  34.  
  35. int length= 0;
  36. byte[] buffer = new byte[1024];
  37. while((length= is.read(buffer,0,1024)) != -1){
  38. os.write(buffer, 0, length);
  39. }
  40. os.flush();
  41. is.close();
  42. os.close();  

你可能感兴趣的:(文件下载)