用struts2实现文件下载的时候,点击下载出来下载选项框,然后点击取消就报了两个异常,如下:
ClientAbortException:  java.net.SocketException: Software caused connection abort: socket write errorjava.lang.IllegalStateException: Cannot call sendError() after the response has been committed但是不会影响程序的运行,求解答struts2异常文件下载

解决方案 »

  1.   

    这个不是点击取消的问题吧。因为取消不会发送请求道服务器,只不过浏览器不再接收这个附件。。
    代码问题导致的,并且使用response 提交了两次
      

  2.   

    /**
     * 下载文件
     * @param filePath 文件路径(物理路径)
     * @param fileName 源文件名称
     */
    public void downLoadFile(String filePath, String fileName) {
    File file = new File(filePath);
    if (!file.exists() || file.isDirectory()) {
    return;
    }
    InputStream input =null;
    OutputStream output = null;
    try {
    input = new FileInputStream(file);
    output = response.getOutputStream();
    response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
    byte[] buffer = new byte[1024];
    int i = 0;
    while ((i = input.read(buffer)) != -1) {
    output.write(buffer, 0, i);
    }
    } catch (Exception e) {} finally {
    try {
    if(null !=output) {
    output.flush();
    output.close();
    }
    if(null !=input) {
    input.close();
    }
    } catch (Exception e) {}
    }
    }
    用这个方法试试