After doing some research online on the subject I currently managed to get things working with this code:
@RequestMapping(value = "/report040Generated", method = RequestMethod.GET)
public String index(Model model, HttpServletResponse response, HttpServletRequest request) throws IOException {
String myString = "Hello";
response.setContentType("text/plain");
response.setHeader("Content-Disposition","attachment;filename=myFile.txt");
ServletOutputStream out = response.getOutputStream();
out.println(myString);
out.flush();
out.close();
return "index";
}
My proble is that when I click on my JSP button, the files gets downloaded but the method doesn't redirect to the "index" .jsp view and gives me an IllegalStateExcepton:
SEVERE: Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutputStream() has already been called for this response
Any suggestions about what might be causing this issue ?