Download the file in Spring MVC in responseentity mode as follows:
@RequestMapping ("/download") public responseentity<byte[]> Download (httpservletrequest request, @RequestParam ("FileName") String fileName) throws IOException { string path = Request.getservletcontext (). Getrealpath ("/uploadimages/"); File Dwfile = new file (path+file.separator+filename); Httpheaders headers = new Httpheaders (); Download the displayed Chinese name, solve the Chinese name garbled problem String downloadfilename = new String (Filename.getbytes ("UTF-8"), "iso-8859-1"); Application/octet-stream: Binary stream data headers.setcontentdispositionformdata ("attachment", downloadfilename); Headers.setcontenttype (mediatype.application_octet_stream); return new Responseentity<byte[]> (Fileutils.readfiletobytearray (dwfile), headers, httpstatus.created);} }
Spring MVC resposeentity Download file