读书人

jfreechart为什么没生成连接解决方法

发布时间: 2012-01-26 19:40:46 作者: rapoo

jfreechart为什么没生成连接
我是在struts框架里面做的,不知道jsp页面里面为什么没生成连接,请大家帮帮忙。
action代码如下。

Java code
public final class ViewProcessOrderAction extends Action{      public ActionForward execute(        ActionMapping mapping,        ActionForm form,        HttpServletRequest request,          HttpServletResponse response) throws Exception {               DynaActionForm searchForm = (DynaActionForm) form;                 String keyword = (String)searchForm.get("keyword");        Integer pageId = (Integer)searchForm.get("pageId");        HttpSession session = request.getSession(true);                List processOrdertList=new DBOperate().getMatchProcessOrders(keyword);                if (processOrdertList.size()==0){                       ActionErrors errors = new ActionErrors();            errors.add(ActionErrors.GLOBAL_MESSAGE,                new ActionError("errors.noMatch"));            if (!errors.isEmpty()) {                saveErrors(request, errors);            }               return  mapping.findForward("toWrong");          }                else{            response.setContentType("text/html;charset=GBK");             PrintWriter out = response.getWriter();              DefaultPieDataset data = new DefaultPieDataset();                        for(int i=0;i<processOrdertList.size();i++){                Order order = (Order)processOrdertList.get(i);                data.setValue(order.getTime(), order.getPrice());            }            PiePlot3D plot = new PiePlot3D(data);//3D饼图             plot.setURLGenerator(new StandardPieURLGenerator("barview.jsp"));//设定链接             JFreeChart chart = new JFreeChart("",JFreeChart.DEFAULT_TITLE_FONT, plot, true);             chart.setBackgroundPaint(java.awt.Color.white);//可选,设置图片背景色             chart.setTitle("订单调查表");//可选,设置图片标题             plot.setToolTipGenerator(new StandardPieToolTipGenerator());             StandardEntityCollection sec = new StandardEntityCollection();             ChartRenderingInfo info = new ChartRenderingInfo(sec);             PrintWriter w = new PrintWriter(out);//输出MAP信息             //500是图片长度,300是图片高度             ChartUtilities.writeImageMap(w, "map0", info, false);            String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);             String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;             request.setAttribute("filename", filename);             request.setAttribute("graphURL", graphURL);             ViewList viewList=new ViewList();            viewList.display (processOrdertList,session,pageId,keyword) ;               return (mapping.findForward("toListProcessOrder"));                            }     }}


jsp代码如下

Java code
      <P ALIGN="CENTER">      <%Object graphURL=request.getAttribute("graphURL"); %>      <%Object filename=request.getAttribute("filename"); %>       <img src="<%= graphURL.toString() %>" width=500 height=300 border=0 usemap="#map0">       <%= graphURL.toString()%>      </P>

先谢谢啦

[解决办法]
如果你项目统一都设置了utf-8,我想你的应该没问题

我的这个项目没有统一设置utf-8,项目里用的是编码转换的方法,但是方法考虑了不太周到,就会出现问题。

说一下我的解决方法
因为生成的map在输出的时候,编码用的是utf-8,生成map的时候不需要加任何的转换,然后你会看到热区上的带中文的参数都是一堆百分号,这个没事,接下来,你就要用request来获取这个参数,再次强调用一下,如果你项目统一用的是utf-8,那么你获取之后的值应该是正确的

我的没有设置,默认的字符集是iso-8859-1,所以需要把iso-8859-1再转成utf-8
只需按下面的就ok了
String pars = request.getParameter("map中传过来的带百分号的中文参数");


par = new String(pars.getBytes("iso-8859-1"),"utf-8");

par的值就变成正确的值了,呵呵,你试试


虽然所有问题都搞定了,但是放在struts调用生成图表,那个输出流和map问题还是个迷,你要是搞好了,告诉我下哦!

读书人网 >J2EE开发

热点推荐