日期:2014-05-18  浏览次数:20827 次

在tomcat中如何配置jfeechart???(在线等)
如题,我照网上说的,
下载了jfreechart-1.0.5.zip,
将jfreechart-1.0.5.zip中的lib路径下的jar文件拷贝到tomcat的common/lib路径下,
修改tomcat的conf/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>
<url-pattern> /servlet/DisplayChart </url-pattern>
</servlet-mapping>

测试demo文件:http://localhost:8000/mydesign/jfreechart.jsp
(我改了端口)
jfreechart.jsp代码:

<%@   page   contenttype= "text/html;charset=gbk "%>
<%@   page   import= "org.jfree.data.general.defaultpiedataset "%>
<%@   page   import= "org.jfree.chart.jfreechart "%>
<%@   page   import= "org.jfree.chart.plot.pieplot "%>
<%@   page   import= "org.jfree.chart.chartrenderinginfo "%>
<%@   page   import= "org.jfree.chart.servlet.servletutilities "%>
<%@   page   import= "org.jfree.chart.urls.standardpieurlgenerator "%>
<%@   page   import= "org.jfree.chart.entity.standardentitycollection "%>
<%@   page   import= "org.jfree.chart.encoders.sunpngencoderadapter "%>

<%
defaultpiedataset   data   =   new   defaultpiedataset();
data.setvalue( "六月 ",   500);
data.setvalue( "七月 ",   580);
data.setvalue( "八月 ",   828);  
pieplot   plot   =   new   pieplot(data);
jfreechart   chart   =   new   jfreechart( " ",   jfreechart.default_title_font,   plot,   true);
chart.setbackgroundpaint(java.awt.color.white);     //可选,设置图片背景色
chart.settitle( "welcome   to   jfreechart   ! ");   //可选,设置图片标题
chartrenderinginfo   info   =   new   chartrenderinginfo(new   standardentitycollection());
//500是图片长度,300是图片高度
string   filename   =   servletutilities.savechartaspng(chart,   500,   300,   info,   session);
string   graphurl   =   request.getcontextpath()   +   "/servlet/displaychart?filename= "   +   filename;  
%>
<html>
<head>
<title> welcome   to   jfreechart   ! </title>
</head>
<body>
<p   align= "center ">
<img   src= " <%=   graphurl   %> "   width=500   height=300   border=0   usemap= "# <%=   filename   %> ">
</p>
</body>
</html>

但,出现问题啊:
tomcat中报错:

type   Exception   report

message  

description   The   server   encountered   an   internal   error   ()   that   prevented   it   from   fulfilling   this   request.

exception  

org.apache.jasper.JasperException:   /a.jsp(1,1)   Page   directive   has   invalid   attribute:   contenttype
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apach