Flex+Struts2+JSON实现Flex和后台的HTTP Service请求
http://www.fengfly.com/plus/view-191093-1.html
Flex+Struts2+JSON的后台代码我在这就不多说了。不懂得请看我写的上一篇文章《Struts2+JQuery+JSON实现异步交互》那篇文章,后台没有任何变化。
在这着重讲Flex端的实现代码。
第一步:
从http://code.google.com/p/as3corelib/网站中下载as3corelib-.92.1.zip文件并解压,解压后在as3corelib-.92.1\as3corelib-.92.1\lib目录中有一个as3corelib.swc文件,把该文件复制到你的Flex工程的libs目录中。就可以工作了。请看Flex代码:
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx=/mxml">http://www.adobe.com/2006/mxml</A>" fontSize="12" layout="absolute">
- <mx:Script>
- <![CDATA[
- import com.adobe.serialization.json.JSONDecoder;
- import mx.rpc.events.FaultEvent;
- import mx.controls.Alert;
- import mx.rpc.events.ResultEvent;
- internal function sendURL():void{
- //设置HTTPService的url属性为你要访问的Action连接后面dd=new Date().getTime();是为了消除浏览器缓存
- hs.url = /fsj/flexstrutsjson!hdList.action?dd=%+new">http://localhost:8080/fsj/flexstrutsjson!hdList.action?dd="+new</A> Date().getTime();
- //调用HTTPService的send()方法
- hs.send();
- //注册成功事件
- hs.addEventListener(ResultEvent.RESULT,success);
- //注册失败事件
- hs.addEventListener(FaultEvent.FAULT,faultResult);
- }
- //失败事件调用的函数
- internal function faultResult(event:FaultEvent):void{
- //弹出失败信息
- Alert.show(event.fault.message);
- }
- //成功函数
- internal function success(event:ResultEvent):void{
- //把返回的对象转换成字符串
- var userStr:String = event.result.toString();
- //使用刚才加入的swc包包中的类JSONDecoder()把字符串转换成JSONDecoder对象
- var userJson:JSONDecoder = new JSONDecoder(userStr);
- //返回Map的方式
- // var d:Object = userJson.getValue().uerInfoMap;
- // var arryObject:Array=[];
- // for each(var f:Object in d){
- // arryObject.push(f);
- // }
- // userInfo.dataProvider = arryObject;
- //返回List的处理方式
- //使用JSONDecoder对象的getValue方法返回对象
- userInfo.dataProvider = userJson.getValue().userInfos;
- }
- ]]>
- </mx:Script>
- <!--创建HTTPService对象-->
- <mx:HTTPService id="hs" method="POST" showBusyCursor="true"/>
- <!--创建发送按钮并调用sendURL()函数-->
- <mx:Button id="requstDate" click="sendURL()" label="发送" x="95" y="78"/>
- <!--创建DataGrid控件来绑定返回的数据-->
- <mx:DataGrid x="95" y="131" width="482" height="270" id="userInfo">
- <mx:columns>
- <mx:DataGridColumn headerText="用户名" dataField="userName"/>
- <mx:DataGridColumn headerText="密码" dataField="pwd"/>
- <mx:DataGridColumn headerText="Email" dataField="email"/>
- <mx:DataGridColumn headerText="年龄" dataField="age"/>
- </mx:columns>
- </mx:DataGrid>
- </mx:Application>
需要注意的是:在JSON的数据量比较大的情况下该方法执行的速度会比较慢。
相关文章:http://www.infoq.com/cn/articles/flex-xml-json
Flex+Struts2+JSON实现Flex和后台的HTTP Service请求的更多相关文章
- struts2 java.lang.StackOverflowError org.apache.struts2.json.JSONWriter
1. 问题描述: 页面通过异步访问action, action的方法通过map封装数据,struts的result的type设置为json,后台报错 六月 25, 2016 6:54:33 下午 ...
- Android+struts2+JSON方式的手机开发(Login)
在手机的后台服务无论是调用WebService还是Http请求,多数都是采用Android的HttpClient实现相关的调用实现.本文实现Android+Struts2+JSON方式实现为手机前台提 ...
- Json在前台与后台之间的使用
一.将前台数据,使用ajax中的post.get传到后台 $.ajax({ type: 'post', url: 'your url', data: $("form").seri ...
- Class org.apache.struts2.json.JSONWriter can not access a member of class org.springframework.aop.TruePointcut with modifiers "public"
Spring注入Action使用Json错误:org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: ...
- org.apache.struts2.json.JSONWriter can not access a member of class
偶遇一个问题:org.apache.struts2.json.JSONWriter can not access a member of class org.apache.tomcat.dbcp.db ...
- Jqgrid入门-结合Struts2+json实现数据展示(五)
DEMO用的是ssh框架实现的,具体怎么搭建的就不多做说明了.分页表格的数据操作难点就是数据展现.至于增删改直接用hibernate原生的方法实现即可. 初步分析:表格要实现分页,那么 ...
- Class org.apache.struts2.json.JSONWriter can not access a member of
异常形式: Class org.apache.struts2.json.JSONWriter can not access a member of * 或是 Class com.googlecode. ...
- struts2 json 定义全局Date格式
使用struts2的json插件时,自己定义日期格式经常使用的方式是在get属性上加入@JSON注解,这个对于少量Date属性还能够,可是假设date字段多了,总不可能去给每一个date get方法加 ...
- Class org.apache.struts2.json.JSONWriter can not access a member of class oracle.jdbc.driver.Physica
产生这个错误的原因是因为我的oracle数据库中有一个CLOB字段,查询出来的时候要转换为JSON而报错. Class org.apache.struts2.json.JSONWriter can n ...
随机推荐
- docker集成管理工具-shipyard的开发环境搭建笔记
前段时间一直在研究openstack,后来老师告诉我需要用docker容器来搭建hadoop集群,所以就将战场转移到docker上来了,话说docker最近这段时间太火了,但是说实话我觉得应用起来还不 ...
- js运动 模仿淘宝幻灯
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- jquery让一个点击事件刷新页面就自己执行一次的方法
$('name')这个元素之前已经绑定过事件啦,(on绑定)然后直接调用下即可: $('name').click();
- 查看80端口被占用的方法(IIS、apmserv、system)
端口如果被其他程序占用就不能正常启动,比如有时启动时会提示WEB启动失败,其实就是80 端口被占用了,而迅雷等下载软件恰恰就是占用了80端口,关掉就行了.但有时迅雷等都没有开 也启动不了,那就是别的东 ...
- 实现LoadRunner多个场景的顺序执行
应用场景假设有3个不同的测试场景,分别为并发登录.核心业务.可靠性测试,3个场景有先后执行顺序.由于白天测试机器另有用处,只能在晚上进行性能测试,这时我们的期望是能否把测试场景都设定好之后晚上自动运行 ...
- does not support ASP.NET compatibility 错误
The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibi ...
- 开发资源列表【Worldsing分享】
ucGUI(emWin)类: ucGui 汉字库生成(汉字库提取工具):ucGuiFont点击下载 ucGui v3.98 VC模拟工程源代码(VS2008):ucGUI3.98 VS2008 点 ...
- bmp格式解析
最近一直在写图像处理的作业,好多啊 bmp格式简介 a.格式组成 1:位图头文件数据结构,它包含BMP图像文件的类型.显示内容等信息: 2:位图信息数据结构,它包含有BMP图像的宽.高.压缩方法,以及 ...
- poj 3134 Power Calculus(IDA*)
题目大意: 用最小的步数算出 x^n 思路: 直接枚举有限步数可以出现的所有情况. 然后加一个A* 就是如果这个数一直平方 所需要的步骤数都不能达到最优 就剪掉 #include < ...
- MRI中T1和T2的含义与区分[转]
A. MRI名词解释 T1加权像.T2加权像为磁共振检查中报告中常提到的术语,很多非专业人士不明白是什么意思,要想认识何为T1加权像.T2加权像,请先了解几个基本概念: 1.磁共振(maget ...