jsp文件下载问题:Connection reset by peer: socket write error
我用以下方法实现资源下载功能:
首先是一个客户端JSP页面,显示可下载的资源列表,当用户点击某个资源是,传递一个唯一的资源编号到Action,在数据库中读取该资源的url,然后下载次数+1,然后把url放到一个request里面,再跳到一个JSP页面:
<%@ page language="java" pageEncoding="GB18030"%><jsp:directive.page import="java.net.URLEncoder"/><% request.setCharacterEncoding("GB18030"); String srcURL = String.valueOf(request.getAttribute("srcURL"));//资源路径 response.setContentType("application/x-download"); String url = "/upload/doc/"+srcURL; String fileName = srcURL; fileName = URLEncoder.encode(fileName, "UTF-8"); response.addHeader("Content-Disposition", "attachment;filename=" + fileName); RequestDispatcher rd = application.getRequestDispatcher(url); rd.forward(request, response); response.flushBuffer(); out.clear(); out.clearBuffer(); out = pageContext.pushBody();%>
2009-8-26 22:06:58 org.apache.catalina.core.ApplicationDispatcher invoke严重: Servlet.service() for servlet jsp threw exceptionjava.net.SocketException: Connection reset by peer: socket write error at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(Unknown Source) at java.net.SocketOutputStream.write(Unknown Source) at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:750) at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:432) at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:347) at org.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:773) at org.apache.coyote.http11.filters.IdentityOutputFilter.doWrite(IdentityOutputFilter.java:118) at org.apache.coyote.http11.InternalOutputBuffer.doWrite(InternalOutputBuffer.java:583) at org.apache.coyote.Response.doWrite(Response.java:560) at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:361) at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:432) at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:347) at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:392) at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:381) at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:89) at org.apache.catalina.servlets.DefaultServlet.copyRange(DefaultServlet.java:2083) at org.apache.catalina.servlets.DefaultServlet.copy(DefaultServlet.java:1796) at org.apache.catalina.servlets.DefaultServlet.serveResource(DefaultServlet.java:874) at org.apache.catalina.servlets.DefaultServlet.doGet(DefaultServlet.java:376) at javax.servlet.http.HttpServlet.service(HttpServlet.java:627) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:461) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:399) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301) at org.apache.jsp.mainViews.downloadAction_jsp._jspService(downloadAction_jsp.java:56) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:461) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:399) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301) at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063) at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194) at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414) at javax.servlet.http.HttpServlet.service(HttpServlet.java:627) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) at java.lang.Thread.run(Unknown Source)2009-8-26 22:06:58 org.apache.catalina.core.StandardWrapperValve invoke
tbmly.setMIsdel("0");//
tbmly.setMReportTime(StringUtil.strToDate(mreporttime));//
tbmly.setMTemp1(mupplace);//
tbmly.setMReportType(mreportype);//
tbmly.setMUploadTime(tbx.getMUploadDate());//
tbmly.setMUploadUser(tbx.getMUploadUser());//
try {
daoTool.saveOrUpdate(tbmly);//
} catch (RuntimeException ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("错误发生了哎!!¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥" + ex);
}
System.out.println("00000000000000000000000000000000000"+tbmly.getMReportTime());
String mttime=StringUtil.dateToStr(tbmly.getMReportTime(),"yyyy-MM-dd");//
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"+mttime);
String hql="from TBmpMtdept as a where a.MTemp='"+mttime+"'and a.MTemp1='"+tbmly.getMReportType()+"'";//
List list001=daoTool.find(hql);
//在这里加个上传时间的判断就是没有及时回复和没回复的就区分出来了;时间大于要求的时间就不保存了;
TBmpMtdept tbdept=new TBmpMtdept();//
if(list001.size()>0){
tbdept=(TBmpMtdept)list001.get(0);
//对于删除后重复上传的的地市编号 要判断是否存在了 要是存在 就不需要再加入这个地市编号了;
tbdept.setMDeptNumber(tbdept.getMDeptNumber()+" "+tbmly.getMFileName().substring(8, 11));//
try{
daoTool.saveOrUpdate(tbdept);
}catch (RuntimeException ex) {
ex.printStackTrace();
}catch(Exception ex){
ex.printStackTrace();
System.out.println("倒霉这里出错了哎!!1》》》》》》》》》》》》》》》》》》》》》》" + ex);
}
}else{
tbdept.setMDeptNumber(tbmly.getMFileName().substring(8, 11));//地市号码集
tbdept.setMIsdel("0");
tbdept.setMTemp(StringUtil.dateToStr(tbmly.getMReportTime(),"yyyy-MM-dd"));//周报时间
tbdept.setMTemp1(tbmly.getMReportType());//报表类型
tbdept.setMTemp2(StringUtil.dateToStr(tbmly.getMUploadTime(),"yyyy-MM-dd hh:mm:ss"));//上传时间
try{
daoTool.saveOrUpdate(tbdept);
}catch (RuntimeException ex) {
ex.printStackTrace();
}catch(Exception ex){
ex.printStackTrace();
System.out.println("倒霉这里出错了哎!!2<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<," + ex);
}
}
我的上传