Struts+Jquery+json实现的ajax案例
来源:互联网 发布:淘宝评价记录能删除吗 编辑:程序博客网 时间:2024/05/19 00:35
方便新手学习的简单案例
首先准备齐全以下几个jar包
commons-beanutils-1.8.3.jar
commons-collections-3.2.jar
commons-lang-2.4.jar
ezmorph-1.0.6.jar
json-lib-2.2.3-jdk15.jar
1、Action方法的写法
public String show_detail() {Map map = new HashMap(); //用于封装各种java变量的容器,方便json统一格式化String s = "s";showLfb = layoutManager.findLfbWithJlbh(jlbh);if (showLfb.getLf().getFloor().equals("-2")) {showLfbLcxx = "品牌位于负二层";}if (showLfb.getLf().getFloor().equals("-1")) {showLfbLcxx = "品牌位于负一层";}showLfbleft = Integer.parseInt(new java.text.DecimalFormat("0").format(showLfb.getDpleft() * clintWidth))+ mainMargin- 5+ Integer.parseInt(new java.text.DecimalFormat("0").format(showLfb.getDpwidth() * clintWidth));showLfbtop = Integer.parseInt(new java.text.DecimalFormat("0").format(showLfb.getDptop() * clintHeight));map.put("pplogo", showLfb.getPplogo());map.put("ppname", showLfb.getPpname());map.put("jlbh", showLfb.getJlbh());map.put("showLfbLcxx", showLfbLcxx);map.put("showLfbleft",showLfbleft );map.put("showLfbtop", showLfbtop);map.put("s", s);JSONObject jsonObject = JSONObject.fromObject(map); //将map封装为json对象msg = jsonObject.toString(); //这个是在action定义的私有String变量,专门用于存放json字符串的System.out.println(jsonObject);return "detail";}
2、struts.xml 配置 result
<result name="detail" type="json"><param name="root">msg</param> <!-- msg就是action里定义的那个存放json字符串的string变量 --></result>
3、jquery调用
$(".lfb").bind("click",function(){var url = "hlds!show_detail.action";var params = {jlbh:this.id,clintHeight:clintHeight,clintWidth:clintWidth};$.post(url,params,function(data){var obj = eval("("+data+")");$("#details").css({ "top": obj.showLfbtop, "left": obj.showLfbleft}).show();$("#details").html('<img id="mages" src="ppImage/'+obj.pplogo+'" style="width:90px;heigth:40px"/><br/><br/>'+obj.ppname+'<br/><s:property value="showLfbLcxx"/>');$("#details").bind("click",function(){self.location='hlds!show_lfb.action?jlbh='+obj.jlbh;});},"json");
- Struts+Jquery+json实现的ajax案例
- Struts+JQuery实现ajax并返回json数据
- Struts学习笔记(三)Ajax +json+JQuery的综合使用
- Struts2+Spring 整合成功测试案例----利用jquery+Json实现简单的Ajax的效果(二)
- Ajax + JQuery + JSON + Struts使用例子
- jquery对象转化json--struts--ajax
- Struts+Jquery+Ajax+Json应用实例
- [Javascript][jQuery]jQuery + json 实现的简易Ajax调用
- JQuery的Ajax请求实现局部刷新 小案例
- .NET+jQuery+JSON实现Ajax
- .NET+jQuery+JSON实现Ajax
- 如何实现完美的表单验证?js? jquery? struts? ajax?
- jquery的ajax语法案例
- 项目中的一个JQuery ajax实现案例
- jquery 的ajax请求传递json数据给struts的action
- jquery ajax的实现 操作json xml jsonp
- 基于jQuery的AJAX和JSON实现纯
- Struts2+jquery+Ajax实现json数据的传输
- easy ui学习篇之validbox
- android 开启闪光灯小应用
- PythonChallenge 挑战之路 Level-11
- IDA 学习笔记
- java--GUI(图形用户接口)
- Struts+Jquery+json实现的ajax案例
- 插入排序
- COM笔记-CoCreateInstance
- android http post 方法
- SQL Server,Access数据库查询易混点和C#中parameter指定参数长度的优缺点
- RMAN高级功能之存储脚本
- Display web JSP page section by section
- 实现MySQL数据库数据的同步方法介绍
- 传智播客C++课程体系介绍