/**
* 模板下载时的文件名如果是中文,需要转码
*
* @param request
* @param oldFileName
* @return
* @throws UnsupportedEncodingException
*/
public static String encodeFileName(HttpServletRequest request,
String oldFileName)
throws Exception {
String userAgent = request.getHeader("User-Agent").toUpperCase();
if (userAgent.indexOf("MSIE") > -1 || userAgent.indexOf("TRIDENT") > -1
|| userAgent.indexOf("EDGE") > -1) {// ie情况处理
oldFileName = URLEncoder.encode(oldFileName, "UTF-8");
// 这里的编码后,空格会被解析成+,需要重新处理
oldFileName = oldFileName.replace("+", "%20");
} else {
oldFileName = new String(oldFileName.getBytes("UTF-8"),
"ISO8859-1");
}
return oldFileName;
}
网友评论