处理下载时候显示文件名中有中文的问题
2015-12-11 14:48
92 查看
此文章就是淡出的处理中文名,下载代码网上多的是,此处不写啦。
public String getStr(HttpServletRequest request, String realFileName)
throws Exception {
String browName = null;
String clientInfo = request.getHeader("User-agent");
System.out.println(clientInfo);
if (clientInfo != null && clientInfo.indexOf("MSIE") > 0) {//
// IE采用URLEncoder方式处理
if (clientInfo.indexOf("MSIE 6") > 0
|| clientInfo.indexOf("MSIE 5") > 0) {// IE6,用GBK,此处实现由局限性
browName = new String(realFileName.getBytes("GBK"),
"ISO-8859-1");
} else {// ie7+用URLEncoder方式
browName = java.net.URLEncoder.encode(realFileName, "UTF-8");
}
} else {//其他浏览器
browName = new String(realFileName.getBytes("GBK"), "ISO-8859-1");
}
return browName;
}
String fileName = getStr(req, attachmentView.getOldName());
response.setCharacterEncoding("GB2312");
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
public String getStr(HttpServletRequest request, String realFileName)
throws Exception {
String browName = null;
String clientInfo = request.getHeader("User-agent");
System.out.println(clientInfo);
if (clientInfo != null && clientInfo.indexOf("MSIE") > 0) {//
// IE采用URLEncoder方式处理
if (clientInfo.indexOf("MSIE 6") > 0
|| clientInfo.indexOf("MSIE 5") > 0) {// IE6,用GBK,此处实现由局限性
browName = new String(realFileName.getBytes("GBK"),
"ISO-8859-1");
} else {// ie7+用URLEncoder方式
browName = java.net.URLEncoder.encode(realFileName, "UTF-8");
}
} else {//其他浏览器
browName = new String(realFileName.getBytes("GBK"), "ISO-8859-1");
}
return browName;
}
String fileName = getStr(req, attachmentView.getOldName());
response.setCharacterEncoding("GB2312");
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
相关文章推荐
- mplayer
- PHP php中数据合并“+”与array_merge()的区别
- Contains Duplicate
- vim ---- 自己主动的按钮indent该命令
- 开发者必知的8款App快速开发工具
- Swift 闭包的简单学习
- Infer的docker版本安装 on Mac
- 在visual studio2015中如何使用localDB具体讲解
- 关于UIImagePickerController和AVCaptureSession的理解
- linux基础(十三)----linux编程基础----linux运算符
- linux基础(十三)----linux编程基础----linux运算符
- android应用程序安装后点击打开带来的问题
- keeping background service alive after user exit app
- EasyUI combobox插件注意事项
- 免费安装制作程序 Inno Setup
- C#获取当前程序运行路径的方法集合
- HDU 1087 Super Jumping! Jumping! Jumping!
- iOS开源项目大全(一)(整理自网络)
- CC2541之OAD问题总结
- 【Android】设备工具类(DeviceUtil.java)