springmvc 文件下载
jopen
9年前
<p>@RequestMapping("/download.htm") </p>
public ResponseEntity<byte[]> download(HttpServletRequest request, @RequestParam("fileId") String fileId) throws IOException {
String path="E:\\Users\\xc\\workspace\\ldassetWeb\\WebRoot\\js\\time.js";
File file=new File(path);
HttpHeaders headers = new HttpHeaders();
String fileName=new String("文件.js".getBytes("UTF-8"),"iso-8859-1");
headers.setContentDispositionFormData("attachment", fileName);
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED);
}
<a href="${ctx}/system/download.htm?fileId=188">下载</a>