response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName) + "\"");试试

解决方案 »

  1.   

    lz用下面的代码试试,
    以下代码再电脑上的各种浏览器都是可以用的, 而且下载输出的文件名可以是中文
    在android手机浏览器使用,貌似有点问题
    /**
     * 下载
     * @param filePath 文件路径(物理路径)
     * @param fileName 输出的文件名
     */
    public static void downLoad(String filePath, String fileName) {
    downLoad(new File(filePath), fileName);
    }

    /**
     * 下载
     * @param file 文件
     * @param fileName 输出的文件名
     */
    public static void downLoad(File file, String fileName) {
    try {
    if (file.exists() && file.isFile()) {
    downLoad(new FileInputStream(file), fileName, file.length());
    }
    } catch (Exception e) {
    log.error("下载", e);
    throw new MvcException(e.getMessage());
    }
    }

    /**
     * 下载
     * @param input 输入流
     * @param fileName 输出的文件名
     * @param fileSize 文件大小
     */
    public static void downLoad(InputStream input, String fileName, long fileSize) {
    try {
    HttpServletResponse response = HttpThread.getResponse();// 线程池中取出response
    String agent = HttpThread.getRequest().getHeader("USER-AGENT").toLowerCase();
    String name = new String(fileName.getBytes(agent.indexOf("msie") != -1 ? "GBK" : CharEncoding.UTF_8), CharEncoding.ISO_8859_1);
    response.setHeader("Content-disposition", "attachment;filename=" + name);
    response.setContentType("application/octet-stream");
    response.setHeader("Content-Length", "" + fileSize);
    OutputStream output = response.getOutputStream();
    byte[] buffer = new byte[1024];int i = 0;
    while ((i = input.read(buffer)) != -1) {
    output.write(buffer, 0, i);
    }
    input.close();output.flush();output.close();
    } catch (Exception e) {
    log.error("下载", e);
    }
    }
      

  2.   

    再加一句:response.setContentType("application/x-download");
      

  3.   

    这个貌似还是不行,是不是前端有什么细节没注意到?
    楼主是用ajax提交的吗,不能用ajax提交的哦,只能用类似  window.location.href    之类的 
      

  4.   

    那么有可能是你前端问题    BufferedInputStream bi = new BufferedInputStream(new FileInputStream(tempFileName));   
        OutputStream os = response.getOutputStream();    
        response.reset();
        response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
        response.setContentType("application/x-msdownload");
    byte buffer[] = new byte[1024];  
    int size;  
    while ((size = bi.read(buffer, 0, buffer.length)) != -1) {
    os.write(buffer, 0, size);
    }
        bi.close();
        os.close();
      

  5.   

    这个貌似还是不行,是不是前端有什么细节没注意到?
    楼主是用ajax提交的吗,不能用ajax提交的哦,只能用类似  window.location.href    之类的 
    正解,我就是用的ajax提交的,改成window.location.href提交后顺利完成