我正在使用jsf数组列表根据某些条件检索记录。现在我希望通过Jasper报告打印此数组列表的内容。我按照以下步骤进行操作。
然后我使用以下代码填写并显示pdf报告
JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(this.srchdEmployeesList);
try {
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse response =
(HttpServletResponse) facesContext.getExternalContext().getResponse();
HashMap parameterMap = new HashMap();
JasperFillManager.fillReportToFile("/reports/employeeReports/employeeList.jasper", parameterMap, dataSource);
InputStream reportStream = facesContext.getExternalContext().getResourceAsStream("/reports/employessReports/employeeList.jasper");
ServletOutputStream servletOutputStream = response.getOutputStream();
Class.forName("oracle.jdbc.driver.OracleDriver");
Session hibernateSession = null;
hibernateSession = HibernateUtils.currentSession();
connection = hibernateSession.connection();
facesContext.responseComplete();
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment;");
JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, parameterMap, connection);
connection.close();
servletOutputStream.flush();
servletOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
我收到以下错误消息并且报告未显示
net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: \reports
\employeeReports\employeeList.jasper
Caused by: java.io.FileNotFoundException: \reports\employeeReports
\employeeList.jasper ... 34 more
在这方面的帮助将受到高度赞赏。提前致谢。
答案 0 :(得分:0)
您写道,该报告位于“Web Content / reports / employeeReports / employeeList”中。但是你的代码似乎没有指向那里。您的代码指向“/reports/employeeReports/employeeList.jasper”。
是否像使用相对路径一样简单?
“reports / employeeReports / employeeList.jasper”或“./reports/employeeReports/employeeList.jasper”