从后端向前端传递数据到ajax_第1页
从后端向前端传递数据到ajax_第2页
从后端向前端传递数据到ajax_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1•创建Java工程vhtmltable7傅srcvrHcom.googledemain』Person.javaw-bcoin.google,servlet?3DdtaConverlerServkJRFSystemIihr^ry宀&ApacheTomcatv7.0[Ap吕WebAppLibrariesMJSTL1.2Libraryjs插件引入highcharts.jsjquery-1.8.3.min.jsmyjs.js引入js插件引入highcharts.jsjquery-1.8.3.min.jsmyjs.js引入ajax*3j$国highcharts.js£)jquery-1.8,3.minjs、心METAINF>OWEDdNrindex.jsp2•前端代码<%@pageIanguage="java"import="java.util.*"pageEncoding="UTF-8"%><%Stringpath=request.getContextPath();String basePathrequest.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>VDOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><basehref="<%=basePath%>"><titIe>MyJSP'index.jsp'startingpage</title><metahttp-equiv="pragma"content="no-cache"〉<metahttp-equiv="cache-control"content="no-cache"〉<metahttp-equiv="expires"content="O"><metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"><metahttp-equiv="description"content="Thisismypage"><!--<linkrel="stylesheet"type="text/css"href="styles.css">--><scripttype="text/javascript"src="js/jquery-1.8.3.min.js"></script><scripttype="text/javascript"src="js/highcharts.js"></script><scripttype="text/javascript"src="js/myjs.js"></script><script>

$(function(){varjsonstr=''varxmlHttp=getXmlHttpRequest();xmlHttp.onreadystatechange=function(){if(xmlHttp.readyState==4&&xmlHttp.status==200){{jsonstr=eval("("+xmlHttp.responseText+")");$('#container').highcharts({chart:{type:'column'},title:{text:'游戏人物状态'},xAxis:{//指定x轴分组categories:['血量','攻击//指定x轴分组},yAxis:{title:{text:'something'}},series:jsonstr/*},series:jsonstr/*[{name:'奥特曼',data:[400,32,40]//指定数据列//数据列名//数据},{name:'怪兽boss',data:[1000,17,25]}]*/}]});}};xmlHttp.open("get","dataConverterServlet",true);xmlHttp.send();});</script></head><body><divid="container"style="min-width:800px;height:400px;"></div>}}</body></html>3.后端代码:throwspublicclassDataConverterServletextendsHttpServlet{throwspublicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)ServletException,IOException{request.setCharacterEncoding("utf-8");response.setContentType("text/html;charset=utf-8");response.setCharacterEncoding("utf-8");PrintWriterout=response.getWriter();StringjString="["+"{name:'奥特曼',data:[800,32,40]},"+"{name:'怪兽boss',data:[1000,27,25]}"+"]";out.print(jString);//将文本传递到前端ajax}throwspublicvoiddo

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论