我必须为用户提供 Excel 下载功能。
这是我的控制器代码片段
@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();
}
}
}
运行上述代码后,我在浏览器上打印垃圾值,而不是在 excel 文件保存/打开弹出窗口上?
是什么原因 ?有什么办法可以解决?