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);
HttpServletRequest request = ServletActionContext.getRequest();