It is necessary to make a report in excel, which would be loaded by clicking on the link, using Spring MVC and JExcel Api. When you click on the link, the controller catches the transition and the report generation method in the service starts, however, as a result, nothing happens in the browser. What's wrong?
Controller:
@RequestMapping(value = "/download", method = RequestMethod.GET) public ModelAndView generateScheduleReport(HttpServletResponse response) { reportService.createExcelOutputExcel(response); return null; } Service:
@Slf4j @Service public class ReportService implements ExcelOutputService{ public WritableWorkbook createExcelOutputExcel(HttpServletResponse response) { String fileName = "Excel_Output.xls"; WritableWorkbook writableWorkbook = null; try { response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); writableWorkbook = Workbook.createWorkbook(response.getOutputStream()); WritableSheet excelOutputsheet = writableWorkbook.createSheet("Excel Output", 0); addExcelOutputHeader(excelOutputsheet); writeExcelOutputData(excelOutputsheet); writableWorkbook.write(); writableWorkbook.close(); } catch (Exception e) { log.error("Error occured while creating Excel file", e); } return writableWorkbook; } ... }