分ie和firefox/oprea不同而不同,红色部分解决编码后空格变+号的问题。
String browser = request.getHeader("user-agent");
Pattern pattern = Pattern.compile(".* MSIE.*?;.*");
Matcher matcherAccount = pattern.matcher(browser);
if(matcherAccount.matches()){
response.setHeader("Content-Disposition","attachment;filename=\""+ [color=red]StringUtils.replace[/color](java.net.URLEncoder.encode(downloadname),"+","%20") + "\"");
}else{
response.setHeader("Content-Disposition", "attachment;filename=\""+ new String(downloadname.getBytes("UTF-8"),"ISO8859-1")+ "\"");
}
解决文件名编码问题
本文介绍了一种针对不同浏览器(IE、Firefox、Opera等)在下载文件时出现的文件名编码错误的解决方案,特别是如何避免文件名中的空格被错误地转为加号+的情况。
1211

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



