今天折腾了一遍Struts2和JasperReport。主要参考了Apache Struts 2 Documentation的JasperReports Tutorial。
中间有一处要注意。struts2包还要加入struts2-jasperreports-plugin-2.0.11.jar(在struts2发布包的lib目录下可以找到)这个包。 一直被这个害了,调了半天,都是诡异的错误。 后来发现,还得要这个包。
如果不加入包struts2-jasperreports-plugin-2.0.11.jar。很可能的错误是下面这个
message There is no Action mapped for namespace / and action name xxx.
另外,注意的是,JasperCompileManager.compileReportToFile()这个函数里面的两个参数最好应绝对路径。当然绝对路径可以用ServletActionContext获取。
另外调试时,注意eclipse的控制台的报错。
主要参考资料
struts2官方的JasperReport入门
在Struts2中使用JasperReports生成报表
struts2整合jasperreport学习笔记