因为在struts2-jfreechart-plugin-2.1.8.jar文件中的struts-plugin.xml文件中,发现该配置中代码如下:
<?xml version="1.0" encoding="UTF-8"?>
...
....
....
<struts>
<package name="jfreechart-default" extends="struts-default">
<result-types>
<result-type name="chart" class="org.apache.struts2.dispatcher.ChartResult">
<param name="height">150</param>
<param name="width">200</param>
</result-type>
</result-types>
</package>
</struts>
所以不用手动配置了,这是struts2.1.8的好处啊。
但是仍然必须注意几下几点:
如果需要ACTION中的统计图表能被STRUTS2处理,则要求该JFreeChart类型的属性名只能为chart.(必须提供getChart()方法,且该方法返回JFreeChart对象)。
步骤:
在Action中需要声明一个JFreeChart变量,变量名称只能为chart。
提供getChart()方法,且该方法返回JFreeChart对象。
在页面上
<tr>
<td colspan="4" >
<img src="orgViewReport.do?orgId=<s:property value="orgId"/>">
</td>
</tr>
在struts.xml中添加配置如下:
<!-- 报表区域 -->
<package name="zhangyu" extends="jfreechart-default">
<action name="orgViewReport" class="OrgViewAction">
<result type="chart">
<param name="height">600</param>
<param name="width">800</param>
</result>
</action>
</package>
完成。