页面:
<img alt="" src="<%=request.getContextPath()%>/https/mystruts/test_view_picture.html" />
urlRewrite:
<rule>
    <from>^/https/mystruts/test_view_picture.html$</from>
    <to>/pages/mystruts/testViewPicture.action</to>
</rule>
struts-config:
<package name="pic" extends="jfreechart-default" namespace="/pages/mystruts">
   <action name="testViewPicture" class="com.ito.hsr.action.get.TestViewPictureAction" method="getChart">
<result name="success" type="chart">
          <param name="width">600</param>
         <param name="height">450</param>
        </result>
    </action>
</package>
public class TestViewPictureAction extends ActionSupport{ public JFreeChart getChart(){
        JFreeChart chart = ChartFactory.createPieChart3D(
"图书统计图", // 图表标题
    getDataSet(), //数据
    true, // 是否显示图例
    false, //是否显示工具提示
    false //是否生成URL
);
//重新设置图标标题,改变字体
   chart.setTitle(new TextTitle("图书统计图", new Font("黑体", Font.ITALIC , 22)));
   //取得统计图标的第一个图例
   LegendTitle legend = chart.getLegend(0);
   //修改图例的字体
   legend.setItemFont(new Font("宋体", Font.BOLD, 14));
   //获得饼图的Plot对象
   PiePlot plot = (PiePlot)chart.getPlot();
   //设置饼图各部分的标签字体
   plot.setLabelFont(new Font("隶书", Font.BOLD, 18));
   //设定背景透明度(0-1.0之间)
        plot.setBackgroundAlpha(0.9f);
   //设定前景透明度(0-1.0之间)
        plot.setForegroundAlpha(0.50f);
        System.out.println("chart===="+chart);
   return chart;
}
private DefaultPieDataset getDataSet(){
   DefaultPieDataset dataset = new DefaultPieDataset();
   dataset.setValue("Spring2.0",47000);
   dataset.setValue("J2EE",38000);
   dataset.setValue("Ajax",31000);
   dataset.setValue("JavaScript",29000);
   dataset.setValue("Ajax In Action",25000);
   return dataset;
}
}

解决方案 »

  1.   

    运行后报错java.lang.ClassCastException: org.jfree.chart.JFreeChart
      

  2.   

    检查你引入的jfreechart的包版本,新的jfreechart包package路径有改变
      

  3.   


    <package name="jFreeChartDemonstration" extends="struts-default" namespace="/jfreechart"> <result-types> 
        <result-type name="chart" class="org.apache.struts2.dispatcher.ChartResult"></result-type> </result-types> 
      <action name="JFreeChartAction" class="com.tangjun.struts2.JFreeChartAction"> 
        <result     type="chart"> 
          <param name="width">400</param>
          <param name="height">300</param> 
        </result>
      </action> 
    </package>
    LZ,你配置错误了。<action name="testViewPicture" class="com.ito.hsr.action.get.TestViewPictureAction" method="getChart"> 
    <result name="success" type="chart"> 
    <param name="width">600</param> 
    <param name="height">450</param> 
    </result> 
    </action>
    这样当然要报类转换错误了,你这个是String,action返回的时候是JfreeChart。
      

  4.   


    不明白你的意思,我的配置哪块出错了,还有我返回的应该是JFreeChart对象,不是String。
      

  5.   


    楼主返回的JFreeChart对象,但是action必须返回字符串对象才行,所以出现类型转换错误