我有report1.jrxml,它有简单的SQL查询,没有参数,在iReport中运行正常。我想通过ADF打开这份报告。 我的reportAction方法如下:
public void reportAction(FacesContext ctx,OutputStream output) throws FileNotFoundException,NamingException,
SQLException, IOException, JRException,
ClassNotFoundException,
InstantiationException,
IllegalAccessException {
File input = null;
Connection conn = null;
Map reportParameters = new HashMap();
bindings = this.getBindings();
ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse)ctx.getExternalContext().getResponse();
String reportPath = ctx.getExternalContext().getInitParameter("reportpath");
input = new File(reportPath+"report1.jasper");
if(bindings!=null){
OperationBinding ob = bindings.getOperationBinding("getCurrentConnection");
ob.execute();
conn = (Connection)ob.getResult();
if(input.getPath()!=null&&reportParameters!=null&&conn!=null){
JasperPrint print = JasperFillManager.fillReport(input.getPath(),reportParameters,conn);
response.addHeader("Content-disposition", "attachment;filename=report1.pdf");
output = response.getOutputStream();
String userName = "ilpa";
File outPutPDF = new File("D:/jdev libs/reports/report1.pdf");
JasperExportManager.exportReportToPdfStream(print, output);
JasperExportManager.exportReportToPdfFile(print,outPutPDF.getPath());
JasperExportManager.exportReportToPdfStream(print, output);
output.flush();
output.close();
}
}
else{
ctx.addMessage(null,new FacesMessage("No bindings configured for this page"));
}
}
可能出现什么问题?
答案 0 :(得分:0)
我自己解决了这个问题。
根本原因是我在web.xml中给出了错误的路径。
也就是说,我在两个位置都有report1.jrxml。我使用的实际报告位于不同的位置。