【问题标题】:Report opens Blank in ADF报告在 ADF 中打开空白
【发布时间】:2012-05-07 08:11:12
【问题描述】:

我有 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"));
}
}

可能出了什么问题?

【问题讨论】:

  • 你查看iReport的报告了吗?
  • 是的。它在 iReport 中运行。
  • 其实我已经更正了上面的异常。这是因为使用了 .jrxml 文件。我已将其替换为 .jasper。现在出现了一个新异常,它是 net.sf.jasperreports.engine.JRException: java.io.UTFDataFormatException: Invalid UTF8 encoding
  • 您应该更正这个问题。能发一下jrxml文件吗?
  • 为什么你使用JRXmlLoader.load来加载jrxml文件?你可以这样使用代码:JasperReport jasperReport = JasperCompileManager.compileReport(path + "\\report.jrxml"); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params); JasperExportManager.exportReportToPdfFile(jasperPrint, outputFileName);

标签: jasper-reports


【解决方案1】:

我自己解决了这个问题。

根本原因是我在 web.xml 中给出了错误的路径。

也就是说,我在两个位置都有 report1.jrxml。我使用的实际报告位于不同的位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多