问题描述
问题分析
浏览器匹配与编码问题。
解决方案
request.setCharacterEncoding("UTF-8");
//response.setContentType("application/octet-stream");
response.addHeader("content-Type", "application/octet-stream" );
String filename = request.getParameter("filename");
String agent = request.getHeader("User-Agent");
if(agent.toLowerCase().indexOf("firefox")!=-1) {
response.addHeader("content-Disposition", "attachment; filename==?UTF-8?B?" + new String(Base64.encodeBase64("问题".getBytes("UTF-8")))+"?=");
}else {
response.addHeader("content-Disposition", "attachment; filename=" + URLEncoder.encode("问题","UTF-8"));
}
运行结果
教学资源
https://www.bilibili.com/video/av29086718?p=37
参考文章
https://blog.csdn.net/cungudafa/article/details/90340016
https://blog.csdn.net/qq_28096687/article/details/53432733
https://blog.csdn.net/mayuanxiaonong/article/details/21230547