解决struts2在(IE,Firefox)下载文件名乱码问题

/**
     * 乱码出现的原因 ie采用URLEncoder编码输出中文 opera采用filename safari采用iso-8859-1
     * chrome采用base64或iso-8859-1 firefox采用base64或iso-8859-1
     */
    public static String downToUtf8String(String s) throws Exception {
        HttpServletRequest request = ServletActionContext.getRequest();
        String agent = request.getHeader("User-Agent");
        System.out.println("agent.toUpperCase():" + agent.toUpperCase());
        agent = agent.toLowerCase();
        if (agent.indexOf("firefox") != -1) {
            s = new String(s.getBytes(), "iso8859-1");
        } else {
            s = java.net.URLEncoder.encode(s, "UTF-8");
        }
        return s;
    }
原文地址:https://www.cnblogs.com/zt528/p/4958851.html