2012-02-27 74 views
0

我有report1.jrxml,它具有简单的SQL查询,没有参数并且在iReport中运行良好。我想通过ADF打开这份报告。 我reportAction方法如下:报告在ADF中打开空白

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

您是否在'iReport'中检查报告? – 2012-02-27 06:36:51

+0

是的。它在iReport中工作。 – 2012-02-27 06:41:51

+0

其实,我已经纠正了上面的异常。这是因为使用了.jrxml文件。我用.jasper替换了它。现在发生了一个新的异常,它是net.sf.jasperreports.engine.JRException:java.io.UTFDataFormatException:无效的UTF8编码 – 2012-02-27 06:57:20

回答

0

我自己解决了这个问题。

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

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