@RequestMapping("/download2")
public void download2(String url,HttpServletResponse res,HttpServletRequest req) throws Exception{
//System.out.println(req.getCharacterEncoding());
String fname=new String(url.getBytes("ISO-8859-1"),"UTF-8");
File _file = new File(fname);
String fileName=_file.getName().substring(14);
String agent = (String)req.getHeader("USER-AGENT");
if(agent != null && agent.indexOf("MSIE") == -1) {
fileName = "=?UTF-8?B?" + (new String (Base64.encodeBase64(fileName.getBytes("UTF-8")))) + "?=";
}else {
// IE
fileName = new String(fileName.getBytes("GBK"), "ISO-8859-1");
}
downFile(res, new FileInputStream(_file),fileName );
}
public void download2(String url,HttpServletResponse res,HttpServletRequest req) throws Exception{
//System.out.println(req.getCharacterEncoding());
String fname=new String(url.getBytes("ISO-8859-1"),"UTF-8");
File _file = new File(fname);
String fileName=_file.getName().substring(14);
String agent = (String)req.getHeader("USER-AGENT");
if(agent != null && agent.indexOf("MSIE") == -1) {
fileName = "=?UTF-8?B?" + (new String (Base64.encodeBase64(fileName.getBytes("UTF-8")))) + "?=";
}else {
// IE
fileName = new String(fileName.getBytes("GBK"), "ISO-8859-1");
}
downFile(res, new FileInputStream(_file),fileName );
}
HTTP下载文件的编码转换与适配
本文探讨了在HTTP请求中下载文件时遇到的编码问题,详细介绍了如何通过编码转换解决不同浏览器间的文件名显示不一致的问题,并提供了代码实现。
350

被折叠的 条评论
为什么被折叠?



