没明白你的意思,重新组织一下你的语言,下载是指下载什么?

解决方案 »

  1.   

    我用servlet写的一个下载程序代码,当servlet走完转到jsp页面的时候会弹出一个下载确认的对话框。
    当我点击对话框上的打开按钮时,会再次弹出对话框,再点击一次打开按钮才会真的打开文件。
    我的代码如下:
     try {
    String fileName=null;
    String fileUrl=null;
    fileUrl=struct.getRealFileName();
    // fileName=struct.getGA1_FILE_NM();
    int indexs = fileUrl.lastIndexOf("/");
    if (indexs != -1) {
        fileName = fileUrl.substring(indexs + 1);
    }
    //      fileUrl = CoreTools.getContainer().getString                                
                                ("nis.screen.pattern.fileupload.dir");
    //      if (fileUrl == null || fileUrl.length() == 0) {
    // fileUrl = "C:\\OrteusProj\\upload\\";
    // }
    response.reset(); 
    response.setContentType("application/x-msdownload"); 
    response.addHeader("Content-Disposition","attachment; filename=\"" + fileName + "\""); 
    File file = new File(fileUrl); 
    if(file.exists()){        
         FileInputStream in = new FileInputStream(file);            
         OutputStream out = response.getOutputStream(); 
         byte[] b = new byte[100];
         int len;
         while ((len = in.read(b)) > 0) {
              out.write(b, 0, len);
         }
         if(in!=null){
              in.close();
          }
         if(out!=null){
              out.close();
          }
                }
            } catch(Exception e) {
                e.printStackTrace();
            }
    是我的contentType没具体指定吗?请指教。谢谢