JasperReports: How to call the report in jsp page

前端 未结 6 621
迷失自我
迷失自我 2020-11-27 21:02

I made one jasper report using iReport 3.7.4 version, now i have to use that or call that report in my java application where i am using servlets, jsp and strut

6条回答
  •  旧时难觅i
    2020-11-27 21:58

    Best solution (For better performance as well), will be calling a compiled report.

    you can see the example below

    import java.io.IOException;
    import java.util.HashMap;
    
    import net.sf.jasperreports.engine.JREmptyDataSource;
    import net.sf.jasperreports.engine.JRException;
    import net.sf.jasperreports.engine.JasperExportManager;
    import net.sf.jasperreports.engine.JasperFillManager;
    import net.sf.jasperreports.engine.JasperPrint;
    
    public class PdfFromJasperFile {
      public static void main(String[] args) throws JRException, IOException {
    
        JasperPrint jasperPrint = JasperFillManager.fillReport("report.jasper",  new HashMap(), 
        new JREmptyDataSource());
        JasperExportManager.exportReportToPdfFile(jasperPrint, "sample.pdf");
    
      }
    }
    

提交回复
热议问题