我正在开发 Spring Web 应用程序,在我的一个控制器中,我编写了代码来处理一些东西并写出 jasper 报告。此代码工作正常,但有时它会抛出上述异常。我正在正确关闭所有输出流,但我仍然收到此错误,知道我哪里出错了。?
这是我的控制器中的代码
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }, value = "/export.do")
public String display(ModelMap model, HttpServletRequest request, HttpServletResponse response,@RequestParam(required = false, value = "type") String type,
@RequestParam(required = false, value = "jrxml") String jrxml) throws IOException {
Map imagesMap = new HashMap();
String sum=request.getParameter("typ");
request.getSession().setAttribute("IMAGES_MAP", imagesMap);
SearchCriteria criteria = (SearchCriteria) request.getSession() .getAttribute("searchCriteria");
criteria.setPageSize(500000);
criteria.setPage(0);
BillingHistoryInputinput=BillingHistoryInput)request.getSession().getAttribute("input");
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
Map<String,Object> datas = generateData(criteria, request, input);
if (StringUtils.isEmpty(type))
type = "xlsx";
if (!type.equals("html") && !(type.equals("print"))) {
response.setHeader("Content-Disposition","attachment;filename= billinghistory." + type);
}
response.setContentType(MimeUtil.getContentType(type));
Map<String, Object> params = (Map<String,Object>)datas.get("params");
if (!type.equals("print")&&!type.equals("pdf")) {
out = dynamicReportService.generateStaticReport("billinghistory",
(List)datas.get("data"), params, type, request);
}
else if (type.equals("pdf")) {
out = dynamicReportService.generateStaticReport("billinghistorypdf",
(List)datas.get("data"), params, type, request);
}
else {
out = dynamicReportService.generateStaticReport("billinghistory"+"print", (List)datas.get("data"), params, type, request);
}
out.writeTo(response.getOutputStream());
criteria.setPageSize(500);
out.flush();
out.close();
return null;
}
catch (Exception e) {
e.printStackTrace();
log.warn("Unable to create file :" + e);
request.getSession().setAttribute("errors", e.getMessage());
return "error";
}
}