I need to create an action in my controller to generate excel file. The problem is that if error occurs, the page is changed but I would like to stay on the same page showing that error.
I have this action in my controller:
@RequestMapping(value="/excel", method = RequestMethod.POST)
public String generateExcel(HttpServletResponse response, Model model)
I would like to stay on the same page in case of error:
if(noError){
// generate Excel
response.setHeader("Content-disposition","attachment; filename= "excel.xls");
response.setContentType("application/vnd.ms-excel");
//...
return "";
} else {
// stay on the same page and show error
// TODO
return ?;
}
My excel generation is working fine but when error occurs, the new page is shown. I can't make ajax call to generate excel. Can someone help me?