日期:2014-05-17  浏览次数:21291 次

Struts2向JasperReport传参数配置

Recently I spent a whole day searching for solutions and experimenting with? solutions for? how to pass additional report parameters? to a Jasper Report from the Struts 2 framework . It took 8 hours because I had to piece together the information that I needed from multiple locations and then I had to experiment and test the solutions in my application .

最近,我花了一整天的时间来寻找和测试如何通过 Struts2向JasperReport传递额外参数的方案。我从多方收集资料,然后在我自己的应用程序里进行测试,为此花了8个小时来拼凑这些信息。

Therefore, I am taking what I have learned and? presenting it here so that others do not have to? a waste a similar amount of time on this in the future.

因此,我把我的解决方法和我所知道的贴出来,以至其他的朋友在这个问题上不会浪费大量的时间。

Step1: Configuring the Struts2 JasperReports Plug-in

The Struts2 JasperReports plug-in makes integrating JasperReports into your application simple and even enjoyable. The following shows how to configure a report using this plug-in .

步骤1:配置Struts2配置文件以支持 JasperReports插件

Struts2的JasperReports插件可以在你的应用程序里制作简单而又有趣的综合报表。下面的代码将向你展示如何配置JasperReports插件与Struts2协同工作

译者注: JasperReports 插件在Struts2的完整压缩包里,包名是 struts2-jasperreports-plugin-2.x.x.jar,将其拷贝到WEB项目工程的CLASSPATH下,即 “WebContent\WEB-INF\lib”下。

Struts关于JasperReport的部分配置XML代码:

  1. <package?name="com.olympus.sapg.smtinnovation.action.jasper"?extends="jasperreports-default">
  2. ?????<result-types>
  3. ?????????<result-type?name="jasper"?class="org.apache.struts2.views.jasperreports.
  4. JasperReportsResult"></result-type>
  5. ?????</result-types>
  6. ?
  7. ???? <action?name="pullMaterielBill"?class="com.olympus.sapg.smtinnovation.action.
  8. jasper.PrintPullMaterielBill">
  9. ????? <result?name="success"?type="jasper">
  10. ????????? <param?name="location"