java下載附件的標題亂碼問題(同時相容IE8以上和火狐)
阿新 • • 發佈:2019-06-06
HttpServletRequest request = ServletActionContext.getRequest();
String header = request.getHeader("User-Agent").toUpperCase();
if (header.contains("MSIE") || header.contains("TRIDENT") || header.contains("EDGE")) {
fileName = URLEncoder.encode(fileName, "utf-8");//IE
}else{
fileName = new String(fileName.getBytes(), "ISO8859-1");//FX
}
response.setDateHeader("Expires", 0);
response.setContentType("application/octet-stream;charset=UTF-8");
response.setHeader("Content-disposition","attachment;filename=\"" + fileName + "\"");