@RequestMapping("/testResponseEntity")
public ResponseEntity<byte[]> testResponseEntity(HttpSession session) throws IOException {
byte[] body=null;
ServletContext servletContext=session.getServletContext();
InputStream in=servletContext.getResourceAsStream("/files/test.txt"); //WebRoot下的路径
body=new byte[in.available()];
in.read(body);
HttpHeaders headers=new HttpHeaders();
headers.add("Content-Disposition", "attachment;filename=test.txt");
HttpStatus statusCode=HttpStatus.OK;
ResponseEntity<byte[]> response=new ResponseEntity<byte[]>(body,headers,statusCode);
return response;
}
public ResponseEntity<byte[]> testResponseEntity(HttpSession session) throws IOException {
byte[] body=null;
ServletContext servletContext=session.getServletContext();
InputStream in=servletContext.getResourceAsStream("/files/test.txt"); //WebRoot下的路径
body=new byte[in.available()];
in.read(body);
HttpHeaders headers=new HttpHeaders();
headers.add("Content-Disposition", "attachment;filename=test.txt");
HttpStatus statusCode=HttpStatus.OK;
ResponseEntity<byte[]> response=new ResponseEntity<byte[]>(body,headers,statusCode);
return response;
}