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

用过jfreechart的来帮忙看看一个小问题.
我在一个JSP页面中显示一个用Jfreechart产生的一个饼状图,但是打开JSP页面之后网页上只显示一个小红叉,并没有显示图片.但是在我的tomcat的temp目录下确定生成了我要的饼状图。
错误提示是:
Could not find action or result
There is no Action mapped for namespace / and action name DisplayChart. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)

源代码如下:

<%@ page language="java" contentType="text/html; charset=GB18030"
  pageEncoding="GB18030"%>
<%@ page import="org.jfree.data.general.DefaultPieDataset,org.jfree.chart.ChartFactory
,org.jfree.chart.JFreeChart,org.jfree.chart.servlet.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="image/jpeg; charset=GB18030">
<title>Insert title here</title>
</head>
<body>

<%

DefaultPieDataset dpd = new DefaultPieDataset();

dpd.setValue("管理人员",25);
dpd.setValue("市场人员",25);
dpd.setValue("开发人员",45);
dpd.setValue("其他人员",10);

JFreeChart chart = ChartFactory.createPieChart("某公司组织结构图",dpd,true,false,false);

String fileName = ServletUtilities.saveChartAsPNG(chart,800,600,session);

String url = request.getContextPath() + "/DisplayChart?filename=" + fileName;

System.out.println(url);



%>

<img src="<%= url %>" width="800" height="600">

</body>
</html>

------解决方案--------------------
提示很明确。找不到命名空间下的东西。检查配置文件以及路径
------解决方案--------------------
url不是你那样写的吧
request.getContextPath()+fileName
------解决方案--------------------
我是在struts中使用的,需要配置web.xml文件
<servlet>
<servlet-name>DisplayChart</servlet-name>
<servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DisplayChart</servlet-name>
&