我使用JasperReport制作报表引擎。到目前为止一切正常,但我有一点小姐的理解。在我的代码中,我试图编译模板文件并返回JasperReport对象,如果编译失败,则编译另一个文件并返回错误消息。但是由于某种原因它不起作用。这里是我的代码:JasperReport异常打印
/**
* Generates JasperPrint object from the Template file
* @param Template File Name (String)
* @param Parameters (Map<String, Object>)
* @param Collection of Value Objects (Collection, List, ArrayList)
* @return JasperPrint
*/
private JasperPrint getJRPrint(String tmpltFileLocation, Map<String, Object> params, JRBeanCollectionDataSource dataSource) {
JasperPrint jrPrint = null;
log.info("ReportEngine: compiling " + tmpltFileLocation);
try {
JasperReport jasperReport = JasperCompileManager.compileReport(tmpltFileLocation);
jrPrint = JasperFillManager.fillReport(jasperReport, params, dataSource);
} catch (JRException ex) {
ex.printStackTrace();
return getErrorJRPrint(ex);
}
return jrPrint;
}
private JasperPrint getErrorJRPrint(Exception ex) {
JasperPrint errJrPrint = null;
Map<String, Object> errParams = new HashMap<String, Object>();
errParams.put("errorMessage", ex.getMessage());
try {
JasperReport jasperReport = JasperCompileManager.compileReport(reportFolderName + "errReport.jrxml");
errJrPrint = JasperFillManager.fillReport(jasperReport, errParams);
} catch (Exception ex2) {
ex2.printStackTrace();
}
return errJrPrint;
}
错误模板文件是存在的(我想删除它,它抱怨说,文件丢失,所以可以看到它)。在我的模板文件中,我只是打印错误信息,而且我试图打印一些静态文本,但它不起作用。可能是什么问题呢?
你解决了你的问题吗? – Bozho 2009-11-21 19:33:13