Integrate Crystal Report in Spring MVC

Thursday, August 18th, 2016 (5 Comments)

The most programmers know about Crystal Report.  In this article, we will integrate Crystal Report in Spring MVC.

Crystal Reports allows users to graphically design data connection and report layout, users can select and link tables from a wide variety of data sources, …

In here, we will focus on Crystal report in spring mvc with parameter, without parameter and get data from database.

At first, we must to need Crystal Report library of SAP, we have to download crjava-runtime_12.2.213.zip and unzip.

1. Create Spring crystal report in spring project with structure as below

a) CrystalReport1.rpt file : report without parameter and no datasource, only text HelloWorld

b) oracle_demo_1.rpt file : report without parameter and select datasource (select * from room)

c) oracle_demo_2.rpt file : report with two parameters and select datasource (select * from room where id < {?id}). The first parameter is p_id (param for condition sql statement) and the second parameter is p_name (param for text of report)

 

spring crystal report

spring crystal report

  • Number 1: copy file CRConfig.xml in template folder of crjava-runtime_12.2.213.zip and pase into project, this file will set dynamic path to files crystal report in spring mvc.
  • Number 2: copy crystalreportviewers folder pase into project,  it use to show report with viewer.
  • Number 3: copy all files in lib of crjava-runtime_12.2.213.zip, libraries for crystal report in spring.
  • Number 4: copy crystal-tags-reportviewer.tld in crystalreportviewers folder.

2. Config some xml files for crystal report in spring

pom.xml – Config maven project

servlet-context.xml

web.xml

  • Line 29 – 36: config for crystal report in spring

3. Controller to handle Crystal Report in spring with many way

HelloWorldController.java

  • function callReportDirectly : call directly report CrystalReport1.rpt from report-viewer.jsp file
  • function callReportNoParameter: call report oracle_demo_1.rpt without parameter and get data from database, it will show on viewer (CrystalReportViewer_setResultSet.jsp file)
  • function callReportParameter: call report oracle_demo_2.rpt with parameter and get data from database, it will show on viewer (CrystalReportViewer_setResultSet.jsp file)
  • function callReportPDFParameterInJava: call report oracle_demo_2.rpt, this  function will download pdf file in java
  • function callReportPDFParameterInJSP: call report oracle_demo_2.rpt, this function will show pdf file in report-pdf.jsp file

4. JSP files

hello.jsp

report-pdf.jsp

report-viewer.jsp

CrystalReportViewer_setResultSet.jsp : show report on viewer

All config above, we use oracle. If you want change connection to mysql or sql server, you can review in Export Crystal Reports to pdf in java

Download Integrate Crystal Report in Spring MVC

Tags: , , , , ,

Related Posts

spring
How to create quartz spring dynamic in database
spring
Spring mvc mongodb crud users roles
spring
Java spring mvc tutorial on lvtutorial.com
spring
Angularjs spring mvc crud example

Related Posts

spring
How to create quartz spring dynamic in database
spring
Spring mvc mongodb crud users roles
spring
Java spring mvc tutorial on lvtutorial.com
spring
Angularjs spring mvc crud example

5 Comments

  1. Shreekant Sonar

    Hi Vivian,

    How to download Crystal Report related jars.

    Please revert.

    Thanks,
    Shreekant

Leave a Reply

Your email address will not be published. Required fields are marked *