我有一个例外。 “net.sf.jasperreports.engine.JRException:没有提供给导出器的输入源”。
源代码(在jsp文件中):
try {
CustomerReport report = new CustomerReport();
report.setReportType((Integer) session.getAttribute("reportType"));
report.setEndTime((String) session.getAttribute("endTime"));
report.setBeginTime((String) session.getAttribute("beginTime"));
List<CustomerStatistics> stasList =
(List<CustomerStatistics>) session.getAttribute("stasList");
dataSize = stasList.size();
ds = report.getDataSource(stasList).toString();
JasperPrint print = report.getPrint(stasList);
JRHtmlExporter exporter = new JRHtmlExporter();
session.setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, print);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, true);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "../servlets/image?image=");
exporter.exportReport();
} catch (Exception e) {
logger.error(this.getClass(), e);
}
CustomerReport代码:
public JasperPrint getPrint(List<CustomerStatistics> stasList) {
JasperPrint print = null;
FontBuilder boldFont = stl.fontArialBold().setFontSize(12).setFontName("SansSerif");
TextColumnBuilder<String> areaNameColumn = col.column("区域", "areaName", type.stringType());
TextColumnBuilder<Integer> businessConsultColumn = col.column("业务咨询", "businessConsultSum", type.integerType());
TextColumnBuilder<Integer> openReserveColumn = col.column("开通预约", "openReserveSum", type.integerType());
TextColumnBuilder<Integer> complainAcceptColumn = col.column("投诉受理", "complainAcceptSum", type.integerType());
try {
print = report()
.setPageFormat(900, 600, PageOrientation.PORTRAIT)
.setTemplate(Templates.reportTemplate)
.title(Templates.createTitleComponent(title + " [ " + beginTime + " 至 " + endTime + " ]"))
.summary(
cht.bar3DChart()
.setShowValues(true)
.setTitleFont(boldFont)
.setCategory(areaNameColumn)
.series(cht.serie(businessConsultColumn), cht.serie(openReserveColumn), cht.serie(complainAcceptColumn))
.setCategoryAxisFormat(
cht.axisFormat().setLabel("区域"))
)
.pageFooter(Templates.footerComponent)
.setDataSource(getDataSource(stasList))
.toJasperPrint();
} catch (Exception e) {
logger.error("________________**** getPrint() ***____________________");
logger.error(this.getClass(), e);
}
public JRDataSource getDataSource(List<CustomerStatistics> stasList) {
DRDataSource ds =
new DRDataSource("areaName", "businessConsultSum", "openReserveSum", "complainAcceptSum");
for (CustomerStatistics stas : stasList) {
ds.add(stas.getAreaName(), stas.getBusinessConsultSum(),
stas.getOpenReserveSum(), stas.getComplainAcceptSum());
}
return ds;
}
动作功能源代码:
stasList=customerStatisticsService.getCustomerStatisList(map);
if(stasList==null||stasList.size()<=0) {
isNoData = true;
noDataHide = true;
}
HttpSession session = ServletActionContext.getRequest()
.getSession();
session.setAttribute("reportType",reportType);
session.setAttribute("stasList",stasList);
session.setAttribute("reportTitle",reportTitle);
session.setAttribute("beginTime",beginTime);
session.setAttribute("endTime",endTime);
String dir = System.getProperty("user.dir");
session.setAttribute("dir",dir);