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代码:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx=/mxml">http://www.adobe.com/2006/mxml</A>" fontSize="12" layout="absolute">
  3. <mx:Script>
  4. <![CDATA[
  5. import com.adobe.serialization.json.JSONDecoder;
  6. import mx.rpc.events.FaultEvent;
  7. import mx.controls.Alert;
  8. import mx.rpc.events.ResultEvent;
  9. internal function sendURL():void{
  10. //设置HTTPService的url属性为你要访问的Action连接后面dd=new Date().getTime();是为了消除浏览器缓存
  11. hs.url = /fsj/flexstrutsjson!hdList.action?dd=%+new">http://localhost:8080/fsj/flexstrutsjson!hdList.action?dd="+new</A> Date().getTime();
  12. //调用HTTPService的send()方法
  13. hs.send();
  14. //注册成功事件
  15. hs.addEventListener(ResultEvent.RESULT,success);
  16. //注册失败事件
  17. hs.addEventListener(FaultEvent.FAULT,faultResult);
  18. }
  19. //失败事件调用的函数
  20. internal function faultResult(event:FaultEvent):void{
  21. //弹出失败信息
  22. Alert.show(event.fault.message);
  23. }
  24. //成功函数
  25. internal function success(event:ResultEvent):void{
  26. //把返回的对象转换成字符串
  27. var userStr:String = event.result.toString();
  28. //使用刚才加入的swc包包中的类JSONDecoder()把字符串转换成JSONDecoder对象
  29. var userJson:JSONDecoder = new JSONDecoder(userStr);
  30. //返回Map的方式
  31. //    var d:Object = userJson.getValue().uerInfoMap;
  32. //    var arryObject:Array=[];
  33. //    for each(var f:Object in d){
  34. //     arryObject.push(f);
  35. //    }
  36. //    userInfo.dataProvider = arryObject;
  37. //返回List的处理方式
  38. //使用JSONDecoder对象的getValue方法返回对象
  39. userInfo.dataProvider = userJson.getValue().userInfos;
  40. }
  41. ]]>
  42. </mx:Script>
  43. <!--创建HTTPService对象-->
  44. <mx:HTTPService id="hs" method="POST" showBusyCursor="true"/>
  45. <!--创建发送按钮并调用sendURL()函数-->
  46. <mx:Button id="requstDate" click="sendURL()" label="发送"  x="95" y="78"/>
  47. <!--创建DataGrid控件来绑定返回的数据-->
  48. <mx:DataGrid x="95" y="131" width="482" height="270" id="userInfo">
  49. <mx:columns>
  50. <mx:DataGridColumn headerText="用户名" dataField="userName"/>
  51. <mx:DataGridColumn headerText="密码" dataField="pwd"/>
  52. <mx:DataGridColumn headerText="Email" dataField="email"/>
  53. <mx:DataGridColumn headerText="年龄" dataField="age"/>
  54. </mx:columns>
  55. </mx:DataGrid>
  56. </mx:Application>

需要注意的是:在JSON的数据量比较大的情况下该方法执行的速度会比较慢。

相关文章:http://www.infoq.com/cn/articles/flex-xml-json

Flex+Struts2+JSON实现Flex和后台的HTTP Service请求的更多相关文章

  1. struts2 java.lang.StackOverflowError org.apache.struts2.json.JSONWriter

    1. 问题描述: 页面通过异步访问action,    action的方法通过map封装数据,struts的result的type设置为json,后台报错 六月 25, 2016 6:54:33 下午 ...

  2. Android+struts2+JSON方式的手机开发(Login)

    在手机的后台服务无论是调用WebService还是Http请求,多数都是采用Android的HttpClient实现相关的调用实现.本文实现Android+Struts2+JSON方式实现为手机前台提 ...

  3. Json在前台与后台之间的使用

     一.将前台数据,使用ajax中的post.get传到后台 $.ajax({ type: 'post', url: 'your url', data: $("form").seri ...

  4. 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: ...

  5. 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 ...

  6. Jqgrid入门-结合Struts2+json实现数据展示(五)

    DEMO用的是ssh框架实现的,具体怎么搭建的就不多做说明了.分页表格的数据操作难点就是数据展现.至于增删改直接用hibernate原生的方法实现即可.         初步分析:表格要实现分页,那么 ...

  7. 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. ...

  8. struts2 json 定义全局Date格式

    使用struts2的json插件时,自己定义日期格式经常使用的方式是在get属性上加入@JSON注解,这个对于少量Date属性还能够,可是假设date字段多了,总不可能去给每一个date get方法加 ...

  9. 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 ...

随机推荐

  1. Cassandra + Eclipse + Hadoop

    配置好eclipse连接hadoop: 参考:http://www.powerxing.com/hadoop-build-project-using-eclipse/ http://blog.csdn ...

  2. 学习内容:Html5+Axure原型设计

    今日主要在http://www.runoob.com/html/html5-intro.html和http://www.imooc.com/learn/9网站上学习Html的知识,head.title ...

  3. Eclipse安装插件的方式

    Eclipse有两种安装插件的方式,分为在线安装和手动安装,因为受到网络环境限制,推荐采用手动安装的方式,下面我们先来了解一下Eclipse手动安装插件的步骤. Eclipse手动安装插件: 第一种: ...

  4. POJ 3164 Command Network (最小树形图)

    [题目链接]http://poj.org/problem?id=3164 [解题思路]百度百科:最小树形图 ]里面有详细的解释,而Notonlysucess有精简的模板,下文有对其模板的一点解释,前提 ...

  5. 关于python all(itrable)的使用 和列表表达式使用以及复习一下短路效应。

    其实现在来看 并不是什么高级特性. 但是当时看到

  6. 可变长参数列表误区与陷阱——va_arg不可接受的类型

    可变长参数列表误区与陷阱--va_arg不可接受的类型 实现一个有可变长参数列表函数的时候,会使用到stdarg.h(这里不讨论varargs.h)中提供的宏. 例如,我们要实现一个简易的my_pri ...

  7. ubuntu官方源列表网址

    http://wiki.ubuntu.org.cn/%E6%BA%90%E5%88%97%E8%A1%A8 (推荐台湾的源)

  8. UVaLive 6608 Cabin Baggage (水题)

    题意:给定四个数代表长宽高和重,问你是不是满足下面条件,长不高于56,宽不宽于45,高不高于25,或者总和不大于125,并且重量不高于7. 析:判断输出就好,注意这个题是或,不要想错了. 代码如下: ...

  9. springMVC在jsp传对象到后台

    ==============实体entity======================= package com.jb.pub.entity; import java.io.Serializable ...

  10. mongodb索引操作

    创建索引 db.table.ensureIndex({name:1}) 创建联合索引 db.table.ensureIndex({"table.name":1,"tabl ...