I am migrating over some legacy servlet code where this pretty much at the end of the code did the download part.
PrintWriter out = null;
out.println("0 " + xyz);
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + test + abc + ".xyz");
I am trying to move this code over to Spring and i'm unable to figure out how my Spring controller should be to get the download working. Right now I have the following
@GetMapping(value = "/testapi/{id}/{mode}")
public @ResponseBody
ResponseEntity<FileSystemResource> test(HttpServletResponse response, @RequestHeader(value = "Authorization") String authHeader,
@PathVariable(value = "id") String id, @PathVariable(value = "mode") String mode) throws Exception {
PrintWriter out = null;
out.println("0 " + xyz);
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + test + abc + ".xyz");
return response;
}
I don't know enough about PrintWriter and how they can be used with Spring Controllers so any guidance here would be appreciated.