工程部署在不同的环境下,以及用不同的浏览器下载附件,编码方式是不同的 下面针对各种情况列出解决的办法:
1、工程在windows环境下时,
ie同firefox:
response.setHeader("Content-Disposition","attachment;" + "filename=" + new String(fileName.getBytes(),"ISO8859-1"));
2、工程在Linux环境下时,
String agent = request.getHeader("USER-AGENT");
if (null != agent && -1 != agent.indexOf("MSIE")){
response.setHeader("Content-Disposition","attachment;" + "filename=" + URLEncoder.encode( fileName , "UTF8"));
}
else if (null != agent && -1 != agent.indexOf("Mozilla")){
response.setHeader("Content-Disposition","attachment;" + "filename=" + new String(fileName .getBytes("UTF-8"),"ISO8859-1"));
}
else {
response.setHeader("Content-Disposition","attachment;filename=" + fileName );
}
1、工程在windows环境下时,
ie同firefox:
response.setHeader("Content-Disposition","attachment;" + "filename=" + new String(fileName.getBytes(),"ISO8859-1"));
2、工程在Linux环境下时,
String agent = request.getHeader("USER-AGENT");
if (null != agent && -1 != agent.indexOf("MSIE")){
response.setHeader("Content-Disposition","attachment;" + "filename=" + URLEncoder.encode( fileName , "UTF8"));
}
else if (null != agent && -1 != agent.indexOf("Mozilla")){
response.setHeader("Content-Disposition","attachment;" + "filename=" + new String(fileName .getBytes("UTF-8"),"ISO8859-1"));
}
else {
response.setHeader("Content-Disposition","attachment;filename=" + fileName );
}