rt 最近在做一个管理系统 要求能产生 柱状图 要求从severlet输出   
然后 就在网上找了一些 资料 这是我做的
下载包什么的都做好了 然后之前做了一个直接从jsp输出的测试成功了 现在要求从severlet输出   
1.首先配置了web.xml文件 增加了如下东西:(不知道这个在从severlet输出有什么用 暂时加上了)  <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>
2.下面的是后台代码   
public class jfreechart_2103 extends HttpServlet {
public jfreechart_2103() {
super();
}public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
  System.out.println("99999999999999999999999999999999999999");
response.setContentType("image/jpeg");CategoryDataset dataset = getDataSet2();
JFreeChart chart = ChartFactory.createBarChart3D(
"水果产量图", // 图表标题
"水果", // 目录轴的显示标签
"产量", // 数值轴的显示标签
dataset, // 数据集
PlotOrientation.VERTICAL, // 图表方向:水平、垂直
true, // 是否显示图例(对于简单的柱状图必须是false)
false, // 是否生成工具
false // 是否生成URL链接
);ChartUtilities.writeChartAsJPEG(response.getOutputStream(),
100,chart,400,300,null);
}
/**  * 获取一个演示用的组合数据集对象  * @return  */
private static CategoryDataset getDataSet2() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(500, "北京", "苹果");
dataset.addValue(100, "上海", "苹果");
dataset.addValue(100, "广州", "苹果");
dataset.addValue(200, "北京", "梨子");
dataset.addValue(200, "上海", "梨子");
dataset.addValue(200, "广州", "梨子");
dataset.addValue(300, "北京", "葡萄");
dataset.addValue(300, "上海", "葡萄");
dataset.addValue(300, "广州", "葡萄");
dataset.addValue(400, "北京", "香蕉");
dataset.addValue(400, "上海", "香蕉");
dataset.addValue(400, "广州", "香蕉");
dataset.addValue(500, "北京", "荔枝");
dataset.addValue(500, "上海", "荔枝");
dataset.addValue(500, "广州", "荔枝");
dataset.addValue(320, "山东", "蔬菜");
return dataset;
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
  System.out.println("99999999999991231231231299");
doGet(request,response);
}
public void init() throws ServletException {
// Put your code here
  System.out.println("999999999999999999999222222222222222222299999999999999999");
}}
3.前台是
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>  
<%  
String path = request.getContextPath();  
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
%>  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>  
  <head>  
  <base href="<%=basePath%>">  
    
  <title>My JSP 'index.jsp' starting page</title>  
<meta http-equiv="pragma" content="no-cache">  
<meta http-equiv="cache-control" content="no-cache">  
<meta http-equiv="expires" content="0">   
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
<meta http-equiv="description" content="This is my page">  
<!--  
<link rel="stylesheet" type="text/css" href="styles.css">  
-->  
  </head>  
   
  <body>  
  This is my JSP page. <br>  
  <img src="./jfreechart_2103"/>  
  </body>  
</html>  
结果显示的图片是叉叉 大侠们帮忙解决下 没想法的捧个人场