I have to give a functionality to user for excel download.
Here is my controller code snippet
@RequestMapping(value = "downloadFIReport.do", method = RequestMethod.GET)
public void downloadFIReport(@RequestParam("recieptID") String recieptId,HttpServletResponse response) {
HSSFWorkbook wb = BillExcelCreator.createFIBillExcel(recieptId);
if(wb != null){
//Writing file to outputstream
try
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
wb.write(bos);
response.setContentLength(bos.size());
wb.write(response.getOutputStream());
// response.flushBuffer();
}
catch(IOException ex) {
ex.printStackTrace();
}
}
}
After running the above code i get garbage value printed on browser instead on excel file save/open pop-up ?
What is the reason ? What can be a solution ?
You are not setting the file to be a downloadable thing. Thats the reason, it is printing some garbage value in the response.
Please check after adding the below lines to the response.