response.setContentType("application/x-download");
response.setCharacterEncoding("utf-8");
if (fm != null && fm != null) {
String userAgent = request.getHeader("User-Agent").toLowerCase();
String strHeader = "";
/**
* 1. IE浏览器,采用URLEncoder编码 2. Opera浏览器,采用filename*方式 3.
* Safari浏览器,采用ISO编码的中文输出 4. Chrome浏览器,采用Base64编码或ISO编码的中文输出
* 5. FireFox浏览器,采用Base64或filename*或ISO编码的中文输出
*
*/
// IE使用URLEncoder
String name=fm.getFileName() + "." + fm.getExtName();
if(userAgent.contains("firefox")){
strHeader = "attachment;filename="+new String((name).getBytes("utf-8"), "ISO8859-1");
}else if (userAgent.contains("windows")) {
strHeader = "attachment;filename="+ URLEncoder.encode(name, "UTF-8");
// 其它使用转iso
} else {
strHeader = "attachment;filename="+ new String((name).getBytes("utf-8"), "ISO8859-1");
}
response.addHeader("Content-Disposition", strHeader);
} else {
String fix=FileUtil.getExtension(applySign.getContractStoreId());
response.addHeader("Content-Disposition", "attachment;filename=" + new Date().getTime()+fix);
}
IOUtils.write(data, response.getOutputStream());
IOUtils.closeQuietly(response.getOutputStream());
1. IE浏览器,采用URLEncoder编码
2. Opera浏览器,采用filename*方式
3. Safari浏览器,采用ISO编码的中文输出
4. Chrome浏览器,采用Base64编码或ISO编码的中文输出
5. FireFox浏览器,采用Base64或filename*或ISO编码的中文输出