恩达

可爱的儿子--阳阳坨

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  43 随笔 :: 14 文章 :: 55 评论 :: 0 Trackbacks

在文件下载的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

在网上查了很多相关信息,还是没找到具体办法。有哪位高人指点一下?

posted on 2007-06-13 15:33 恩达 阅读(18252) 评论(7)  编辑  收藏 所属分类: JAVA

评论

# re: ClientAbortException: java.io.IOException异常该如何捕获?[未登录] 2007-06-13 16:27 Jonney
给Tomcat增加APR支持之后就不会出现了。
http://tomcat.apache.org/tomcat-5.5-doc/apr.html  回复  更多评论
  

# re: ClientAbortException: java.io.IOException异常该如何捕获? 2007-06-13 17:12 恩达
现运行的tomcat是有apr支持的,同样还是有这个问题  回复  更多评论
  

# re: ClientAbortException: java.io.IOException异常该如何捕获? 2007-06-13 22:19 lizongbo
加个过滤器,在doFilter里catch IOException 即可.

//Process the request/response pair
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) {
try {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
filterChain.doFilter(request, response);
}
catch (java.io.IOException ex) {
//ClientAbortException是IOException
log.error(request.getRemoteAddr() + " io error : " + ex);
}
catch (Throwable t) {
log.error("CommonFilter", t);
}
}

  回复  更多评论
  

# re: ClientAbortException: java.io.IOException异常该如何捕获? 2007-07-06 16:07 大灰狼
我也遇到过,但问题不是出现在这,也不知怎么解决的~  回复  更多评论
  

# re: ClientAbortException: java.io.IOException异常该如何捕获? 2007-07-06 20:51 恩达
对代码进行了处理,避免了这个问题的出现,让其在日志里提示错误信息  回复  更多评论
  

# re: ClientAbortException: java.io.IOException异常该如何捕获? 2008-10-21 17:36 fdz
我也遇到了同样的问题,但不知道怎么解决  回复  更多评论
  

# re: ClientAbortException: java.io.IOException异常该如何捕获? 2015-10-30 14:56 mk
也遇到同样的问题,发现是由于迅雷下载打断了正常的下载,后台报出这个错误  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: