版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
12JSON*345注 练习1:级联下拉列表 错误!未定义书签练习2:JSON演示 错误!未定义书签练习3:热卖商品动态显示 练习4:jQuery演示 练习5:select选择器 练习1:级联下拉列表<%@<%@pagecontentType="text/html;charset=utf-8"<title>Inserttitle<scripttype="text/javascript"<scriptgetXmlHttpRequest(){varxhr=XMLHttpRequest)!='undefined'){xhr=newXMLHttpRequest();}elsexhr=new }return}functionvarxhr=getXmlHttpRequest();//服务器返回if(xhr.readyState==vartxt=xhr.responseText;vararr=txt.split(';');$('s2').innerHTML='';vararr1=vararr2=varop=new$('s2').options[i]=}xhr.send('name='+}<option <selectid="s2"packagepackageimportimportimportimportimportimportpublicclassActionServletextendsHttpServletpublicvoidservice(HttpServletRequestrequest,HttpServletResponseresponse){Stringuri=Stringpath=uri.substring(uri.lastIndexOf("/"),PrintWriterout=response.getWriter(); Stringname=}}}}else}}2:JSON演示packagepackagepublicclassOptionprivateStringprivateString}}publicStringgetCityName(){returnpublicvoidsetCityName(StringcityName){this.cityName=publicStringgetCityValue(){returnpublicvoidsetCityValue(StringcityValue){this.cityValue=publicOption()publicOption(StringcityName,StringcityValue)this.cityName=this.cityValue=}JSON的jar请JSON_jar.zip如何将一个javajava对象数组、集合)转换成一个jsonpackagepackageimportimportimportnet.sf.json.JSONArray;importbean.Option;publicclassTest*Java对象->JSONpublicstaticvoidOptionopnewOption("海淀","hd");Stringstr=obj.toString();}*数组对象->JSONpublicstaticvoidOptionop=newOption("海淀","hd");Optionop2=newOption("东城","dc");Optionop3=newOption("西城","xc");Option[]ops={op,op2,op3};Stringstr=obj.toString();}*List对象->JSONpublicstaticvoid}}}publicstaticvoidmain(String[]args)}Stringstr=JSONArrayobj=Optionop=newOption("海淀","hd");Optionop2newOption(Optionop3=newOption("西城","xc");List<Option>opsnewArrayList<Option>();如何将一个json字符串转换成js对象js/prototype-<metahttp-equiv="Content-Type"<title>Inserttitle<scripttype="text/javascript"<scriptfunctionf1(){varstr=varobj=str.evalJSON();}functionf2(){varobjs=str.evalJSON();}<ahref="javascript:;"packagepackageimportjava.io.PrintWriter;importjava.util.ArrayList;importjava.util.List;importimportbean.Option;publicclassActionServletextendsHttpServletpublicvoidservice(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,{Stringuri=PrintWriterout=response.getWriter();}else}}elseOptionop=newOption("海淀","hd");Optionop2newOption("东城","dc");Optionop3newOptionList<Option>ops=newArrayList<Option>();}}}JSONArrayobj=JSONArray.fromObject(ops);Stringstr=obj.toString();}elseOptionop=newOption("怀化","hh");Optionop2=newOption("长沙","cs");Optionop3=newOption("岳阳","yy");List<OptionopsnewArrayList<Option>();JSONArrayobj=JSONArray.fromObject(ops);Stringstr=obj.toString();}}<%@<%@pagecontentType="text/html;charset=utf-<title>Inserttitle<scripttype="text/javascript"src="js/prototype-<scripttype="text/javascript">getXmlHttpRequest(){varxhr=xhr=newXMLHttpRequest();}elsexhr=newActiveXObject('}return}functionvarxhr=getXmlHttpRequest();if(xhr.readyState==vartxt=xhr.responseText;varcitys=txt.evalJSON();$('s2').innerHTML='';varop$('s2').options[i]=}}xhr.send('name='+}<option <selectid="s2"packagepackageimportpublicclassUserprivateStringname;privateDatebirthday;publicDategetBirthday(){return}}}publicvoidsetBirthday(Datebirthday)this.birthday=}publicStringgetName()return}publicvoidsetName(Stringname)=}packagepackageimportimportimportpublicclassTest2publicstatictest1(){Useruser=newuser.setBirthday(newStringstr=obj.toString();}publicstaticvoidmain(String[]args)//TODOAuto-generatedmethod}} packagepackageimportjava.util.Date;importimport@authorpublicclassDateProcessorimplementsJsonValueProcessor{privateStringpattern="yyyy-publicvoidsetPattern(String{this.pattern=}publicObjectprocessArrayValue(Objectarg0,JsonConfigarg1){SimpleDateFormatsdf=newSimpleDateFormat(pattern);returnsdf.format((Date)arg0);}publicObjectprocessObjectValue(Stringarg0,Objectarg1,JsonConfigarg2){SimpleDateFormatsdf=newSimpleDateFormat(pattern);returnsdf.format((Date)arg1);}}packagepackageimportimportnet.sf.json.JSONObject;importnet.sf.json.JsonConfig;importbean.User;publicclassTest2publicstatictest1(){Useruser=newuser.setBirthday(newDate());JsonConfigconfig=newJsonConfig();JSONObjectobj=Stringstr=obj.toString();}publicstaticvoidmain(String[]args)//TODOAuto-generatedmethod}}packagepackageimportjava.io.PrintWriter;importjava.util.Date;importimportimportjavax.servlet.http.HttpServletRequest;importtest.DateProcessor;importnet.sf.json.JSONObject;importnet.sf.json.JsonConfig;importbean.User;publicclassActionServletextendsHttpServletpublicvoidservice(HttpServletRequestrequest,HttpServletResponseresponse){Stringuri=Stringpath=uri.substring(uri.lastIndexOf("/"),PrintWriterout=response.getWriter();Useruser=newUser();user.setBirthday(newDate());JsonConfigconfig=newJsonConfig();}}}JSONObjectobj=Stringstr=obj.toString();}<%@<%@pagecontentType="text/html;charset=utf-8"<title>Inserttitle<scripttype="text/javascript"src="js/prototype-<scripttype="text/javascript">getXmlHttpRequest(){varxhr=XMLHttpRequest)!='undefined'){xhr=newXMLHttpRequest();}elsexhr=new }return}functionvarxhr=getXmlHttpRequest();if(xhr.readyState==vartxt=$($('d1').innerHTML=++'birthay:'+}}:;"<div练习3:热卖商品动态显示SQL>SQL>createtableprodNamevarchar(50),qtySQL>insertintot_sale(prodName,qty)values('bmwx5',120);SQL>...建立一个web写实体类写dao类SaleDAO,提供一个获得销量前三名的方法。参考sql:select*fromt_saleorderbyqtydesclimit3;写一个Servlet,生成一个jsonfunction}functionfunction}function//使用 }<body新建工程Jar包:SQL>SQL>droptablet_sale;SQL>createtablet_sale(prodNamevarchar(50),qtySQL>SQL>insertintot_sale(prodName,qty)SQL>insertintot_sale(prodName,qty)values(SQL>insertintot_sale(prodName,qty)values('步步高 SQL>insertintot_sale(prodName,qty)values('海尔冰箱',120);SQL>select*fromt_saleorderbyqtydesclimitpackagepackagepublicclass{privateStringname;privateintpublicSale(Stringname,intqty)=this.qty=}publicSale()publicStringgetName(){returnpublicvoidsetName(Stringname){=}}publicvoidsetQty(intqty){this.qty=packagepackageimportjava.sql.ResultSet;importjava.sql.Statement;importjava.util.ArrayList;importjava.util.List;importutil.DBUtil;importpublicclassSaleDAOpublicList<Sale>find()throwsException{List<Sale>sales=newStatementstat=ResultSetrst="select*fromt_saleorderbyqtydesclimit3");}return}}测试(略throwsthrowspackageimportjava.io.PrintWriter;importjava.util.List;importimportimportjavax.servlet.http.HttpServletRequest;importnet.sf.json.JSONArray;importimportpublicclassActionServletextendsHttpServlet{Stringuri=Stringpath=PrintWriterout=response.getWriter();SaleDAOdao=newSaleDAO();try{List<Sale>sales=}catch(Exception{thrownew}}}}}<%@<%@pagecontentType="text/html;charset=utf-8"<title>Inserttitleborder:1pxsolidred;}<scripttype="text/javascript"src="js/prototype-<scripttype="text/javascript">varxhr=null;xhr=newXMLHttpRequest();}elsexhr=new }return}function}functionfunctionvarxhr=getXmlHttpRequest();xhr.onreadystatechange=function(){if(xhr.readyState==vartxt=xhr.responseText;varsales=varsaleInfo'当前销量最好的商品是:<br/>';for(i=0;i<sales.length;i++){sasales[i].namesales[i].qty+}$('d1').innerHTML=}}<bodystyle="font-size:30px;"<div4:jQuery演示新建工程<title>Inserttitle}varobj }functionf2(){varob
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 人教版九年级化学第十单元1常见的酸和碱课时2酸的化学性质分层作业课件
- 护理质控组长竞聘
- 销售提成协议合同范本
- 2024版钢筋工程造价咨询合同2篇
- 司机协议书 3篇
- 离职欠工资结算协议书范本
- 《课程TMA系统篇》课件
- K12教育机构培训内容
- 2024年度店铺门面租赁合同解除协议:约定解除合同的条件2篇
- 回收废油协议书版专业
- 烫金烫印材购销合同
- DXI800分析仪性能保障措施
- 直线导轨的安装步骤公开课一等奖市优质课赛课获奖课件
- 广西职业技术学院教师招聘考试真题2022
- 铁路建设工程质量安全专项整治活动总结(完整版)
- UbuntuLinu操作系统上机实践实验题题库期末考试试卷24
- 邻菲罗啉安全技术说明书MSDS
- 部编版五年级道德与法治上册第三单元《我们的国土我们的家园-我们神圣的国土》第一课时
- GB/T 7284-2016框架木箱
- 脑与认知科学国家重点实验室开放课题申请书
- 国家自然科学基金申请经验汇总课件
评论
0/150
提交评论