求助大虾:当下载页面出现后,点击“保存”没有任何问题,但是点击“打开”却要点击两次才能打开,但是.xls文档只需要点击一次就可以打开,对于.txt/.img/.jpg/.gig/.sql/.properties等文件却要点击两次才能打开?
代码如下:
       String attachID = request.getParameter("attachID");       attachmentMode = attachmentAdapter.getAttachment(attachID);       byte[] content = attachmentMode.getAttachContent();       String fileName = attachmentMode.getFileName();       int fileSize = (new Long(attachmentMode.getAttachSize())).intValue();       java.io.ByteArrayInputStream byteInputStream = 
                                   new java.io.ByteArrayInputStream(content);       javax.servlet.ServletOutputStream out= response.getOutputStream();       response.setHeader("Content-Disposition", "attachment;filename=\""+fileName+"\"");       byte buff[] = new byte[fileSize];       while(byteInputStream.read(buff)!=-1){
out.write(buff);
} out.flush(); byteInputStream.close(); out.close();

解决方案 »

  1.   

    这是我以前编写的代码,给你参考一下吧
    FileInputStream fis = new FileInputStream(strDownloadFileName);
    byte[] b = new byte[fis.available()];
    fis.read(b);
    fis.close();

    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition","attachment; filename="
     + toISO8859_1(strFileName));
    OutputStream out = response.getOutputStream();
    out.write(b, 0, b.length);
    out.close();
      

  2.   

    首先要谢谢你,但是,我始终没有找到原因,主要是点击打开.xls文件时点击一次就可以,但是其他类型文件就要点击两次才能打开。有大虾说是IE内有一些小插件,比如说FLASHGET等,但是我把FLASHGET删掉还是不行。也不知道是否是IE的BUG。