JasperReports: How to call the report in jsp page

前端 未结 6 607
迷失自我
迷失自我 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条回答
  •  失恋的感觉
    2020-11-27 22:01

    1. Compile the report in iReport
    2. Place the compiled report on the classpath
    3. load it with

      JasperReport jasperReport = (JasperReport) JRLoader.loadObject(inputStream);
      
    4. Fill it with data. dataSource is the DataSource instance you have - for example a BeanCollectionDataSource

      JasperPrint jasperPrint = 
           JasperFillManager.fillReport(jasperReport, params, dataSource);
      
    5. Export it

      JRPdfExporter exporter = new JRPdfExporter();
      exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
      exporter.exportReport();
      
    6. The outputStream above may be either a response.getOutputStream() or a FileOutputStream(), depending on whether you want to send it to a client or you want to store it as a file. If you want to send it to the client, you'd have to send the Content-Disposition header, and some more, but that depends on the format you want to save to. In case you want to print on the client, it's quite a different question - you'd need some client-side code, an applet, for example.

提交回复
热议问题