这个我知道啊,我设置的编码方式是UTF-8,但就是在火狐浏览器上行不通

解决方案 »

  1.   

    自己写的servlet还是怎么。如果是自己写的servlet下载的话加上这个试试看
    response.setHeader("Content-Disposition", "attachment; filename=\""+URLEncoder.encode("//文件名", "utf-8//編碼方式")+"\"");
      

  2.   

    这是我的:
    response.addHeader("Content-Disposition","attachment; filename="+ URLEncoder.encode(fileName, "UTF-8"));
      

  3.   

    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/xml这里天MIME类型; charset=UTF-8");试试看,好像csdn用火狐下载也是乱码
      

  4.   

    我也这么写了,也加了“charset=UTF-8”,还是没用
      

  5.   

    在火狐里打about:config找找看有关字符编码的设置看看吧,要是还不行,就无能为力了
      

  6.   

    http://apps.hi.baidu.com/share/detail/21304246
    嗯,试试这个看看
      

  7.   

    最后还是被我自己解决了,先在页面做下判断,判断是什么浏览器,然后传一个参数到servlet,进行用不同的编码方式:
    火狐的:
    response.addHeader("Content-Disposition", "attachment;filename="+ new String(fileName.getBytes("GB2312"),"ISO-8859-1"));
    IE及其他:
    response.addHeader("Content-Disposition", "attachment; filename="+ URLEncoder.encode(fileName, "UTF-8"));
      

  8.   

    //判断当前使用浏览器版本类
    var SysBrowser = function(){
    this.ua = navigator.userAgent.toLowerCase();
    this.browserAndVersion;
    this.verIE ;
    this.verFirefox;
    this.verChrome;
    this.verOpera;
    this.verSafari;
    this.getBrowser = function(){
    (this.browserAndVersion = this.ua.match(/msie ([\d.]+)/)) ? this.verIE = parseInt(this.browserAndVersion[1],10) : 
        (this.browserAndVersion = this.ua.match(/firefox\/([\d.]+)/)) ? this.verFirefox = this.browserAndVersion[1] : 
        (this.browserAndVersion = this.ua.match(/chrome\/([\d.]+)/)) ? this.verChrome = this.browserAndVersion[1] : 
        (this.browserAndVersion = this.ua.match(/opera.([\d.]+)/)) ? this.verOpera = this.browserAndVersion[1] : 
        (this.browserAndVersion = this.ua.match(/version\/([\d.]+).*safari/)) ? this.verSafari = this.browserAndVersion[1] : 0; 
        //以下进行测试 
        if (this.verIE) return "IE"+this.verIE; 
        if (this.verFirefox) return "Firefox";
        if (this.verChrome) return "Chrome";
        if (this.verOpera) return "Opera";
        if (this.verSafari) return "Safari";
        }
    };
      

  9.   

    后台是 C#的话,可以这样弄            Response.Clear();
                string UserAgent = Request.ServerVariables["http_user_agent"].ToLower();
                string FileName = "附件.rar";
                if (UserAgent.IndexOf("firefox") == -1)
                {//非火狐浏览器
                    FileName = HttpUtility.UrlEncode(FileName, Encoding.UTF8);
                }
                string Type = "application/zip";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName);
                Response.AddHeader("Content-Length ", suppliers.Attachment.Length.ToString());
                Response.ContentType = Type;
                Response.ContentEncoding = Encoding.UTF8;
                Response.BinaryWrite(suppliers.Attachment);
                Response.End();
      

  10.   

    suppliers.Attachment 为 Byte[] 文件流
      

  11.   


    //火狐
    if (request.getHeader("User-Agent").toLowerCase().indexOf("firefox") > 0) {
    fileNameTemp = new String(fileNameTemp.getBytes("UTF-8"), "ISO8859-1");
    }
    //IE
    else if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0){
    fileNameTemp = URLEncoder.encode(fileNameTemp, "UTF-8");
    }

    response.setHeader("Content-Disposition", "attachment;filename=\""+fileNameTemp+"\"");
      

  12.   

    刚学jsee,上面好多代码都看不懂。
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    // 获得客户端提交 下载文件绝对路径
    String path = request.getParameter("path");// GET提交中文乱码
    path = new String(path.getBytes("ISO-8859-1"), "utf-8");// 手动解决乱码 String filename = path.substring(path.lastIndexOf("\\") + 1);// 文件名
    // 设置文件类型
    response.setContentType(getServletContext().getMimeType(filename));
    // 设置Content-Disposition
    String agent = request.getHeader("user-agent");
    System.out.println(agent);
    if (agent.contains("MSIE")) {
    // IE浏览器 --- URL编码
    filename = URLEncoder.encode(filename, "utf-8");
    } else if (agent.contains("Firefox")) {
    // 火狐浏览器 --- Base64编码
    filename = base64EncodeFileName(filename);
    } else {
    filename = URLEncoder.encode(filename, "utf-8");
    }
    response.setHeader("Content-Disposition", "attachment;filename="
    + filename); // 将文件内容写入客户端
    InputStream in = new BufferedInputStream(new FileInputStream(path));
    OutputStream out = new BufferedOutputStream(response.getOutputStream());

    int temp;
    while ((temp = in.read()) != -1) {
    out.write(temp);
    }
    in.close();
    out.close();
    } public static String base64EncodeFileName(String fileName) {
    BASE64Encoder base64Encoder = new BASE64Encoder();
    try {
    return "=?UTF-8?B?"
    + new String(base64Encoder.encode(fileName
    .getBytes("UTF-8"))) + "?=";
    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    throw new RuntimeException(e);
    }
    }
    火狐要用base64解决编码问题
      

  13.   

    学习了!但是我想说你确定:response.addHeader("Content-Disposition", "attachment;filename="+ new String(fileName.getBytes("GB2312"),"ISO-8859-1"));
    这句能编译通过?我找到一个方法:
    string outputFileName = null;  
    outputFileName = "\"" + FileName+"\"";
    Response . AddHeader("Content-Disposition" , "attachment;filename=" + outputFileName);
      

  14.   

    String agent = req.getHeader("user-agent");
    resp.setContentType("application/x-download");
    if(agent.contains("Firefox"))
        resp.addHeader("Content-Disposition","attachment;filename="+ new String(displayFileName.getBytes("GB2312"),"ISO-8859-1"));
    else 
        resp.addHeader("Content-Disposition","attachment;filename=" + URLEncoder.encode(displayFileName, "UTF-8"));刚刚我也遇到了这个问题,综合上面的回答,发下我的做法,在IE,谷歌,火狐等浏览器测试没问题!