JAVA文件下载功能在FireFox和IE中的差异(下载文件名中出现空格时,在FireFox中文件名被截断)

HttpServletRequest request = ServletActionContext.getRequest();

String agent = request.getHeader("User-Agent");

boolean isMSIE = (agent != null && agent.indexOf("MSIE") != -1);

if (isMSIE) {

    //IE
    filename= URLEncoder.encode(filename, "UTF-8");
} else {

    //FF
    filename= "=?UTF-8?B?" + (new String(Base64.encodeBase64(filename.getBytes("UTF-8")))) + "?=";  //import org.apache.commons.codec.binary.Base64;
}
response.setHeader("Content-Disposition", "attachment; filename=" + filename);

String agent = request.getHeader("User-Agent");
HttpServletRequest request = ServletActionContext.getRequest();
posted @ 2012-04-20 19:33  秋裤大叔  阅读(655)  评论(0编辑  收藏  举报