我的代码是基于struts的,我想实现在代码里加入Map然后在Jsp页面中的代码有超链接。但是在代码里加入map以后,在jsp页面点击查看源代码,里面没有生成<map>标签。然后在struts action里面添加w.flush();在点击查看源文件,里面生成了<map>标签,但是jsp页面是空白页面,jsp源文件除了<map>标签其他什么代码都没有,大家能帮帮忙指点一下小弟吗?看看怎样能实现我想要的功能!
package com.hit.struts.action;import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.labels.StandardPieToolTipGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.urls.StandardPieURLGenerator;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;import com.hit.bean.Order;
import com.hit.persistence.DBOperate;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());
}
//JFreeChart chart = new JFreeChart("",JFreeChart.DEFAULT_TITLE_FONT, plot, true);
JFreeChart chart = ChartFactory.createPieChart3D("订单调查表", data, true, true, true);
PiePlot3D plot = new PiePlot3D(data);//3D饼图
plot.setURLGenerator(new StandardPieURLGenerator("barview.jsp"));//设定链接
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是图片高度
String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);
ChartUtilities.writeImageMap(w, filename, info, false);
w.flush();
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中实现视频播放?
- HQL
- 如何更改<img的值
- 想往java程序员方向发展,需要学好那些课程
- 高分请教,我在学习 struts in action 中 有点问题 请教高手!
- 请教项目中的用户怎样与工作流shark参与者做映射!谢谢!
- 与a.properties连接不上?
- 求j2ee1.3 tutorial例子的源代码
- jbuilder8+weblogic6.1开发struts出现了ASSERTION FAILED ?
- 请问一下jbuilder和weblogic的高手,怎么样才能不让web.xml不被jbuilder修改里边的内容呢?
- 求一个sns的解决方案
- J2EE如何实现热部署啊
<%Object graphURL=request.getAttribute("graphURL");
Object filename=request.getAttribute("filename");
%>
<img src="<%= graphURL.toString() %>" width=500 height=300 border=0 usemap=<%="#"+filename%>>
<%= graphURL.toString()%>
</P>
<%
String filename = (String)request.getAttribute("filename");
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;%><img src="<%= graphURL %>" align="center" border=0 usemap="#<%= filename %>">
Object graphURL=request.getAttribute("graphURL");
Object filename=request.getAttribute("filename");
得到后输出一下,这两个值得到的都是啥?是不是要改成String的?还有就是你所谓的<map>标签是什么东西,struts1里有这个标签吗?
是指的<img> 里的usemap属性???
虽然是乱写的,但是Object graphURL=request.getAttribute("graphURL");
Object filename=request.getAttribute("filename");
不改也行,也能生成饼图。<map>标签是ChartUtilities.writeImageMap(w, filename, info, false);生成的标签,struts里面没有,这是jfreechart里面的。
是页面基本的标签 就和<tr><td>一样
用来做热点的 不知道还有没有别的用途 我只知道这