日期:2014-05-20  浏览次数:20697 次

JSP页面显示JFreeChart图表的问题
在JSP页面中写了个显示图表的一段代码,然后在Tomcat下的零时目录tmp下已经可以生产图片了,但是在JSP页面中就是现实不出来,可能是路径的问题,可我不知道怎么改,麻烦各位了,JSP页面代码如下

XML code


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="org.jfree.data.general.DefaultPieDataset" %>
<%@ page import="org.jfree.chart.ChartFactory" %>
<%@ page import="org.jfree.chart.JFreeChart,org.jfree.chart.servlet.ServletUtilities" %>
<!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="text/html; charset=UTF-8">
<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() + "D:/tomcat/Tomcat 6.0/temp/DisplayChart?filename=" + fileName;
        
        
 %>
 
 <img src="<%= url %>" width="500" height="300">
</body>
</html>




在页面我查看了源文件,打印的图片地址是
<img src="/st2D:/tomcat/Tomcat 6.0/temp/DisplayChart?filename=jfreechart-29350.png" width="500" height="300">




------解决方案--------------------
我贪心点 这里也来接点分!呵呵,楼主不会吝啬吧!
------解决方案--------------------
看问题,你的 url mapping不对呀,DisplayChart在web。xml写了没有啊
------解决方案--------------------
可以不生成图片的吧,直接用stream