您的位置:首页 > 其它

Excel中文文件名下载

2014-01-06 17:48 411 查看

public static String encodeFileName(String fileName, HttpServletRequest request) {
String agent = request.getHeader("USER-AGENT");
try {
if ((agent != null) && (-1 != agent.indexOf("MSIE"))) {
String newFileName = URLEncoder.encode(fileName, "UTF-8");
newFileName = StringUtils.replace(newFileName, "+", "%20");
if (newFileName.length() > 150) {
newFileName = new String(fileName.getBytes("GB2312"), "ISO8859-1");
newFileName = StringUtils.replace(newFileName, " ", "%20");
}
return newFileName;
}
if ((agent != null) && (-1 != agent.indexOf("Mozilla"))) {
// return MimeUtility.encodeText(fileName, "UTF-8", "B");
return URLEncoder.encode(fileName, "UTF-8");
}
return fileName;
} catch (Exception ex) {
return fileName;
}
}


String fileName = "中文";
fileName = encodeFileName(fileName, request);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "attachment;filename*=utf-8'zh_cn'" + fileName + ".xls");


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: