小弟刚最近学jfreechart,遇到问题。
在lomboz运行jfreechart的小例子,在sample.jsp上点右键运行,在lomboz里弹出的运行界面地址总是出问题:
运行后地址为:http://localhost:8080/JFreeChartTest/DisplayChart/sample.jsp
但是我删除掉:/DisplayChart
运行如下地址则正确:http://localhost:8080/JFreeChartTest/sample.jsp我的项目名是JFreeChartTest,而sample.jsp是建在webcontent文件夹下的。
为什么会多出/DisplayChart,哪里没有配置好呢?我的WEB.XML是:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
JFreeChartTest</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<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>/DisplayChart</url-pattern>   
   </servlet-mapping>   
</web-app>
例子sample.jsp内容是:
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<%request.setCharacterEncoding("GBK");   //确保传入的中文字符被识别%> 
<%@ page import="org.jfree.chart.ChartFactory,org.jfree.chart.JFreeChart,org.jfree.chart.plot.PlotOrientation,
org.jfree.chart.servlet.ServletUtilities,org.jfree.data.category.DefaultCategoryDataset"%>
<%
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(610, "广州", "猪肉");
dataset.addValue(220, "广州", "牛肉");
dataset.addValue(530, "广州", "鸡肉");
dataset.addValue(340, "广州", "鱼肉");
JFreeChart chart = ChartFactory.createBarChart3D("肉类销量统计图","肉类","销量",dataset,PlotOrientation.VERTICAL,false,false,false);
String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, null, session);
String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
%>
<html>
<table>
<tr>
<td>
<img src="<%= graphURL %>"width=500 height=300 border=0 usemap="#<%= filename %>">
</td>
</tr>
</table>
</html>
都是网上的例子,没什么问题。
大家帮我看看问题出在哪里了,非常感谢!

解决方案 »

  1.   

    谢谢了,没有用啊!
    感觉应该是web.xml配置的问题,jfreechart我用的是最新的1.0.13.jar。
    很奇怪的问题!
      

  2.   

        <servlet-mapping> 
            <servlet-name>DisplayChart </servlet-name> 
            <url-pattern>/DisplayChart </url-pattern> 
    </servlet-mapping> 
    改成这样:
    <servlet-mapping> 
            <servlet-name>DisplayChart </servlet-name> 
            <url-pattern>/*.do </url-pattern> 
    </servlet-mapping> 
    试试
      

  3.   

    谢谢啊!你的方法运行后网址成:http://localhost:8080/JFreeChartTest/sample.do
    而且不出结果。
      

  4.   

    <servlet-mapping>
            <servlet-name>DisplayChart </servlet-name>
            <url-pattern>/ </url-pattern>
    </servlet-mapping> 
    那你这样写不就行了么。