日期:2014-05-17  浏览次数:20824 次

页面导出文件时报ClientAbortException: java.io.IOException,这个怎么处理?
RT:我用firefox和ie测试一切正常,用360和搜狗浏览器导出文件就会发生这个问题,但是文件可以正常导出就是后台会抛出这个异常。我在网上搜了一下发现有好多都有这个问题,基本都没有好的解决方法,有的说是tomcat的问题,有的说是因为取消了下载操作引起的。但是貌似都没有给出解决方法。
有木有大神看看这个该怎么解决呢?
以下我的代码:
js:

$("#btnExport").click(function(event) {
                $("#op").val("export");
                $("#pageNo").val(1);
                $("#frmQuery").submit();
                $("#op").val("");
            });

action:

 protected void exportFile(File file) {
        logger.debug("file=" + file);
        ServletOutputStream out = null;
        try {
            byte[] fileData = FileUtils.readFileToByteArray(file);
            String filename = file.getName();

            logger.debug("fileData.length=" + fileData.length);

            HttpServletResponse response = ServletActionContext.getResponse();
            response.addHeader("Content-Disposition", "attachment; filename="
                    + filename);
            response.addHeader("Content-Length", "" + file.length());
            response.setContentType("application/octet-stream");
            out = response.getOutputStream();
            out.write(fileData);
        } catch (Exception e) {
            logger.error("输出文件时出错! " + file.getAbsolutePath(), e);
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
        &nbs