这样的程序为什么不能得到输出?大家来看看(程序不长!!)在线......
bean程序:
package com.lingnan;
import java.awt.Insets;
import java.awt.Font;
import java.io.PrintWriter;
import javax.servlet.http.HttpSession;
import org.jfree.data.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.entity.*;
import org.jfree.chart.urls.*;
import org.jfree.chart.servlet.*;
import org.jfree.chart.labels.StandardPieToolTipGenerator;
public class W {
private DefaultPieDataset data = new DefaultPieDataset();
public void setValue(){
data.setValue("联想", 27.3);
data.setValue("长城", 12.2);
data.setValue("海尔", 5.5);
data.setValue("美的", 17.1);
data.setValue("松下", 9.0);
data.setValue("科龙", 19.0);
}
public String generatePieChart(String title, HttpSession session, PrintWriter pw) {
String filename = null;
try {
//创建chart对象
PiePlot plot = new PiePlot(data);
plot.setInsets(new Insets(0, 5, 5, 5));
//在统计图片上建连结
plot.setURLGenerator(new StandardPieURLGenerator("link.jsp","section"));
plot.setToolTipGenerator(new StandardPieToolTipGenerator());
JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
chart.setBackgroundPaint(java.awt.Color.white);//设置图片的背景色
Font font = new Font("黑体",Font.CENTER_BASELINE,20);//设置图片标题的字体大小
TextTitle title = new TextTitle(title);
title.setFont(font);
chart.setTitle(title);
//把生成的图片放到临时目录
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
//500是图片长度,300是图片高度
filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);
ChartUtilities.writeImageMap(pw, filename, info);
pw.flush();
} catch (Exception e) {
System.out.println("Exception - " + e.toString());
e.printStackTrace(System.out);
filename = "public_error_500x300.png";
}
return filename;
}
}
jsp程序:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import = "java.io.PrintWriter" %>
<%@ page import="com.lingnan.W"%>
<%
W chart = new W();
chart.setValue();
;
String filename = chart.generatePieChart("www.SenTom.net 网站访问统计表", session, new
PrintWriter(out));
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
%>
<HTML>
<HEAD>
<TITLE>www.sentom.net</TITLE>
</HEAD>
<BODY>
<P ALIGN="CENTER">
<img src="<%= graphURL %>" width=500 height=300 border=0 usemap="#<%=filename%>">
</P>
</BODY>
</HTML>
这是一个例子程序,改动也不大,为什么在网页上输出一个大白框而不见图片,是servlet问题吗?大家给点意见..