1. Come up and cope directly
public String setFileDownloadHeader(HttpServletRequest request, HttpServletResponse response, String fileName) throws Exception { String userAgent = request.getHeader("user-agent").toLowerCase(); If (userAgent. The contains (" msie ") | | userAgent. The contains (" like gecko ")) {/ / win10 edge, ie browser and other ie fileName = system URLEncoder.encode(fileName, "UTF-8"); } else { // fe fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1"); } return fileName; }Copy the code
2. Invoked when you set the name of the file to be downloaded
@GetMapping("/download") public String downloadFile(HttpServletRequest request, HttpServletResponse response) { ... FileName = setFileDownloadHeader(request, response, fileName); //. Response. SetContentType ("application/force-download"); //. Response. SetHeader (" content-disposition ", "attachment "); fileName=" + fileName); . }Copy the code
3. Let’s see if he’s still a mess