I am using spring boot. I wrote code to load data into a database. If something goes wrong, the data will be downloaded in pdf format, which is incorrect. I want to do this, I have to download this pdf file and go to another page.
@RequestMapping(value = "/doUpload", method = RequestMethod.POST)
public void doUpload(@ModelAttribute("employeeCsvForm") EmpFileUpload fileUpload,HttpServletRequest request, HttpServletResponse response){
if (errorCount != 0) {
File fileEmp = new File("error.pdf");
if (fileEmp.exists()) {
FileUtils.copyFile(fileEmp, response.getOutputStream());
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment;filename=error.pdf");
response.flushBuffer();
}
}
}
This code downloads the PDF file . But I need to redirect to another page, so I used
response.sendRedirect(request.getContextPath() + "/employee/errorCsv");
after response.flushBuffer();
Its loading pdf is successful , but the following error is displayed .
Error: getOutputStream () has already been called for this answer
When I write a redirect code response.sendRedirect(request.getContextPath() + "/employee/errorCsv");
before response.flushBuffer();
His direction to another page is successful, but it does not load .
I want to do both, I tried my best, but could not. Thanks in advance.