5
我嘗試導出JRXML文件爲PDF格式,但我得到這個錯誤:提供的java.sql.Connection對象爲null
WARN query.JRJdbcQueryExecuter - The supplied java.sql.Connection object is null.
我只得到了一個空白的PDF文件..
這是我的方法導出爲PDF:
public void printReport(ActionEvent event) throws JRException, IOException {
String reportPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/test.jrxml");
JasperReport report = JasperCompileManager.compileReport(reportPath);
JasperPrint jasperPrint = JasperFillManager.fillReport(report, new HashMap<String, String>());
HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.pdf");
ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);
FacesContext.getCurrentInstance().responseComplete();
}
我是新與JasperReports的,所以我有點失去了..我一定要在連接字符串以取消數據庫還是什麼?我應該在哪裏添加它。
順便說一句,我使用JSF 2,intellij和maven。
謝謝。
謝謝。這工作:) –