1. 程式人生 > >java下載附件的標題亂碼問題(同時相容IE8以上和火狐)

java下載附件的標題亂碼問題(同時相容IE8以上和火狐)

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 + "\"");