1.上来直接cope
public static String setFileDownloadHeader(HttpServletRequest request, HttpServletResponse response, String fileName) throws Exception {
String userAgent = request.getHeader("user-agent").toLowerCase();
if (userAgent.contains("msie") || userAgent.contains("like gecko") ) {
// win10 ie edge 浏览器 和其他系统的ie
fileName = URLEncoder.encode(fileName, "UTF-8");
} else {
// fe
fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
}
return fileName;
}
2. 设置下载文件名称时调用
fileName = setFileDownloadHeader(request, response, fileName); // 1.设置文件ContentType类型,这样设置,会自动判断下载文件类型 // response.setContentType("multipart/form-data"); // 2.设置文件头:最后一个参数是设置下载文件名 response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
3.看看他还乱不乱