小弟刚最近学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>
都是网上的例子,没什么问题。
大家帮我看看问题出在哪里了,非常感谢!
在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>
都是网上的例子,没什么问题。
大家帮我看看问题出在哪里了,非常感谢!
解决方案 »
- 如何在MyEclipse中将JSP的Encoding设成GBK!
- 网站计数器代码编写时的疑问
- POI读取WORD文档时一个很奇怪的问题
- 一个关于初学者的理论问题急请高手帮忙
- tomcat显示html页面中文是乱码
- jdbc中我用的是mysql,请问怎样调用jdbcc存储过程
- session中取出的对象内容为何和放进去时的对象内容不同呢
- 高手进来看看
- 用JSP写入MySQL数据库中,英文和数字完全正常,但中文字为“????”,我该怎么办?
- 初学jsp,请教一个简单问题,jsp中有没有像asp中定义application_start,application_end,session_start,session_end事件的文件?
- 急,请各位大虾帮帮忙,关于jsp中用js写的幻灯式图片新闻
- 关于请求frameset页面的问题
感觉应该是web.xml配置的问题,jfreechart我用的是最新的1.0.13.jar。
很奇怪的问题!
<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>
试试
而且不出结果。
<servlet-name>DisplayChart </servlet-name>
<url-pattern>/ </url-pattern>
</servlet-mapping>
那你这样写不就行了么。