在文件下载的servlet的doGet方法中写有如下代码:
response.setContentType(responseType);
// response.setHeader("Content-Disposition", "filename=" + fileName);
response.setHeader( "Content-Disposition", "attachment;filename=" + new String( fileName.getBytes("gb2312"), "ISO8859-1" ) );
OutputStream out = null;
InputStream blobIn = null;
try
{
out = response.getOutputStream();
if (blob != null)
{
blobIn = blob.getBinaryStream();
int readCount;
byte[] bOut = new byte[4096];
while ((readCount = blobIn.read(bOut, 0, 4096)) > 0)
{
blobIn.available();
out.write(bOut, 0, readCount);
}
blobIn.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally{
if(blobIn != null)
blobIn.close();
if(out != null)
out.close();
}
在前台执行文件下载时,如果点IE出来后的文件下载提示框中的“取消”会出来如下的异常。请问该如何捕获?使之不在后台报此错误
ClientAbortException: java.io.IOException
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:358)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:434)
at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:349)
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)
at com.wsoft.application.poststation.service.DownloadFileService.doGet(DownloadFileService.java:118)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.wsoft.application.poststation.service.HibernateAndJbpmSessionFilter.doFilter(HibernateAndJbpmSessionFilter.java:43)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:866)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:716)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1498)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.io.IOException
at org.apache.coyote.http11.InternalAprOutputBuffer.flushBuffer(InternalAprOutputBuffer.java:692)
at org.apache.coyote.http11.InternalAprOutputBuffer$SocketOutputBuffer.doWrite(InternalAprOutputBuffer.java:722)
at org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:126)
at org.apache.coyote.http11.InternalAprOutputBuffer.doWrite(InternalAprOutputBuffer.java:528)
at org.apache.coyote.Response.doWrite(Response.java:560)
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:353)
... 23 more
在网上查了很多相关信息,还是没找到具体办法。有哪位高人指点一下?