调用的方法就是这样
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        File file= new File("c:\\trace\\2003-06-17.log");
        Download.download(response,file);
    }
两次下载就是,提交这个请求之后,首先出现系统中的下载提示框,如果点击保存就出现保存路径的提示框,这个没有问题,但是如果点击打开,就又出现一次系统中的下载提示框,还是问你是保存还是打开的

解决方案 »

  1.   


        public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            File file= new File("c:\\trace\\2003-06-17.log");
            Download.download(response,file);
        }
      

  2.   

    if(!file.exists())
                throw new FileNotFoundException();
            response.setContentType("text/plain");
            response.setHeader("Content-disposition","attachment; filename=" + file.getName());
      

  3.   

    通过get方式,在ie6下不会出现两次窗口,post方式就会出现
      

  4.   

    这样改一下试一试,不用BufferedInputStream和BufferedOutputStream直接用看看可不可以。
    另外看一下客户端的script语言是否写错了,或者做一个更简单的界面直接调用Download,我也以前碰到过类似问题,最后发现是客户端JavaScript中有问题,ie6升级之后才会有这个问题,我也不清楚为什么,语法上是没有什么问题的,反正不知道为什么他总是一下提交两次。
    public class Download {    public static void download(HttpServletResponse response,File file) throws IOException {
            if(!file.exists())
                throw new FileNotFoundException();
            response.setContentType( "application/octet-stream");
            response.setHeader("Content-disposition","attachment; filename=" + file.getName());        InputStream in= new FileInputStream(file);        ServletOutputStream out = response.getOutputStream();        int bytesRead;
            int i_length = in.available();
            byte buf_1[]=new byte[i_length];
            while(i_length>0){
                in.read(buf_1);
                out.write(buf_1);
                i_length=in.available();
            }
            out.close();
            in.close();
        }
    }