文件下载时:
出现的下载提示框,点击打开按钮,在ie6中文件能正常打开,ie7则不行。
要打开的文件格式为 .hel 的
着急 在线等.......
源文件,在页面上直接调用FileDownLoad.java/**************************************************************/
public static boolean FileDownload(String filePath,
                                     String contentType,
                                     PageContext pageContext) throws Exception {
    if (filePath == null || filePath.equals("")) {
      throw new IllegalArgumentException("File '" + filePath + "' not found.");
    }
    if (pageContext == null) {  
      throw new Exception("pageContext is null");  
    }
    //ServletContext servletContext = pageContext.getServletContext();
    File fileInfo = new File(filePath);
    if (!fileInfo.exists()){
      throw new SecurityException("Physical path is denied.");
    }
    HttpServletResponse response = (HttpServletResponse) pageContext.
        getResponse();
    contentType = contentType == null || contentType.equals("") ?
        "application/x-msdownload" : contentType;
    response.setContentType("HLFormat");
    response.setContentLength( (int) fileInfo.length());
    String fileName = fileInfo.getName();
    response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
    FileInputStream inputStream = null;
    OutputStream output = null;
    BufferedInputStream bInputStream = null;
    try {
      inputStream = new FileInputStream(filePath);
      bInputStream = new BufferedInputStream(inputStream, 1024);
      byte[] b = new byte[1024];
      int n = 0;
      output = response.getOutputStream();
      while ( (n = bInputStream.read(b)) != -1) {
        output.write(b, 0, n);
      }  
      output.flush();
      output.close();
      inputStream.close();
      bInputStream.close();
    }
    catch (Exception ex) {
      System.out.println(ex.getMessage() + "------downLoad");
      return false;
    }
    return true;
  }
/**************************************************************/downLoad.jsp
/**************************************************************/<%@ page import="com.ninemax.nacao.util.*" %><%
    String filePath = request.getParameter("filePath");
     
    String s = System.getProperty("user.dir")+filePath;
    s = s.replaceAll("domains","applications").replaceAll("olimpic","olimpic/DefaultWebApp");
    boolean flag = FileDownload.FileDownload(s,"application/HL Image Format",pageContext);
    if(!flag){
    out.println("<script language='javascript'>alert('下载失败');history.back();</script>");
    }
   %>/**************************************************************/