使用jsp页面显示水晶报表还是存在这样的问题:
1. 配置麻烦。
-
水晶报表自身的网页版crytalviewer显示内容存在失真,和实际的不一致。
-
水晶报表的XML文件配置不正确导致无法加载报表文件,难以排除问题。
以下方法可以更加简单的在Spring boot 项目中使用Crytal reports.
在src\main\resources
下创建lib文件夹,并在通过build path
->Add Extern Achives
将水晶报表的依赖库加入到项目中。
此方法管理的lib发布时会出现找不到包的问题,需要使用maven的方式引用,可参考maven项目引用外部jar包的方法
总共有24个jar包, 逐个添加很麻烦, 现将它们列出来, 方便大家复制
<dependency>
<groupId>SAP</groupId>
<artifactId>AzleaUflBarcode</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/com.azalea.ufl.barcode.1.0.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>CommonsCollections</artifactId>
<version>3.1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/commons-collections-3.1.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>CommonsConfiguration</artifactId>
<version>1.2.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/commons-configuration-1.2.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>CommonsLang</artifactId>
<version>2.1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/commons-lang-2.1.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>CommonsLogging</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/commons-logging.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>CrystalCommon2</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/CrystalCommon2.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>CrystalReportsRuntime</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/CrystalReportsRuntime.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>cvom</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/cvom.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>DatabaseConnectors</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/DatabaseConnectors.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>derby</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/derby.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>icu4j</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/icu4j.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>JaiImageio</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/jai_imageio.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>JDBInterface</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/JDBInterface.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>jrcerom</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/jrcerom.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>keycodeDecoder</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/keycodeDecoder.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>log4j</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/log4j.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>logging</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/logging.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>pfjgraphics</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/pfjgraphics.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>QueryBuilder</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/QueryBuilder.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>SapComTcSecCsi</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/sap.com~tc~sec~csi.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>WebreportingJsf</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/webreporting-jsf.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>webreporting</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/webreporting.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>xpp3</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/xpp3.jar</systemPath>
</dependency>
<dependency>
<groupId>SAP</groupId>
<artifactId>Xtreme</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/Xtreme.jar</systemPath>
</dependency>
使用CR4E (Crytal Reports for Eclipse) 提供的CRJavaHelper
灵活操作报表,例如直接用PDF文件预览,以及导出PDF,Word等操作。
使用@RestContorller
创建控制器,设置RequestMapper
, 使用绝对路径加载报表即可
@RestController
public class ReportPOController {
@GetMapping("/Report/PO/showPdf")
public void showPdf()
throws ReportSDKExceptionBase, IOException {
ReportClientDocument reportClientDocument = new ReportClientDocument();
reportClientDocument.open("reports/ReportPO.rpt", 0);
// This will be used by the viewer to display the desired report. True to
// Download this report.
CRJavaHelper.exportPDF(reportClientDocument, response, false);
}
@GetMapping("/Report/PO/exportPdf")
public void exportPdf() throws ReportSDKExceptionBase, IOException {
ReportClientDocument reportClientDocument = new ReportClientDocument();
reportClientDocument.open("reports/ReportPO.rpt", 0);
// This will be used by the viewer to display the desired report. True to
// Download this report.
CRJavaHelper.exportPDF(reportClientDocument, response, true);
}
}
注意:我的项目中, 我在src/main/resource
下创建了一个reports
文件夹,所以上面的报表绝对路径为reports/ReportPO.rpt
,
无需tld标签定义文件, 无需xml配置文件,也不需要加载jsp支持。
来源:oschina
链接:https://my.oschina.net/kshuang/blog/3156379