我正在尝试将 DynamicJasper 5.0.0 与 Struts 2.3.4 一起使用。我使用以下代码以 PDF 格式显示数据:
动作课中:
try {
FastReportBuilder drb = new FastReportBuilder();
DynamicReport dr = drb.addColumn("Size", "size", String.class.getName(), 30).setTitle("Size List Report").setSubtitle("This report was generateed at" + new Date()).setUseFullPageWidth(true) //make colums to fill the page width
.setPrintBackgroundOnOddRows(true).build();
JRDataSource ds = new JRBeanCollectionDataSource(getSizeList());
JasperPrint jp = DynamicJasperHelper.generateJasperPrint(dr, new ClassicLayoutManager(), ds);
JasperViewer.viewReport(jp); //finally display the report report [/CODE]
} catch (Exception e) {
System.out.println("Exception");
}
return SUCCESS;
struts.xml
:
<package name="expotpkg" extends="struts-default, json-default,jasperreports-default">
<result-types>
<result-type name="dynamic-jasper" class="ar.com.fdvs.dj.webwork.DJResult"/>
</result-types>
<action name="DownloadSizePdf" class="iland.work.SizesAction" method="fetchDJ">
<result name="success" type="dynamic-jasper">
<param name="dynamicReport">dr</param>
<param name="dataSource">sizeList</param>
<param name="documentName">Dynamic Report generated with struts 2</param>
<param name="parameters">params</param>
<param name="format">PDF</param>
<param name="layoutManager">classic</param>
</result>
</action>
</package>
运行此程序时,我收到以下错误:
There is no result type defined for type 'dynamic-jasper' mapped with name 'success'. Did you mean 'dynamicJasper'? - result - file:/E:/Project/cxn/cnx/build/web/WEB-INF/classes/struts.xml:571:58
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.buildResults(XmlConfigurationProvider.java:653)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:387)
... 20 more
我已包含以下 jar 文件:
将此配置添加到您的包中
<result-types>
<result-type name="dynamicJasper" class="ar.com.fdvs.dj.webwork.DJResult"/>
</result-types>
<action name="DownloadSizePdf" class="iland.work.SizesAction" method="fetchDJ">
<result name="success" type="dynamicJasper">
<param name="dynamicReport">dr</param>
<param name="dataSource">sizeList</param>
<param name="documentName">Dynamic Report generated with struts 2</param>
<param name="parameters">params</param>
<param name="format">PDF</param>
<param name="layoutManager">classic</param>
</result>
</action>
ActionSupport
类位于包名称com.opensymphony.xwork2
下。该错误是由于您与 Struts2 一起使用的插件配置与您使用的 Struts 版本不兼容而发生的。