我使用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