RPC通信之HTTPService(Java-flex)
2017-02-08 22:13
477 查看
<!-- 一、 Flex 封装/发送、接收/解析 Json --> <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <fx:Style source="Regist.css"/> <fx:Script> <![CDATA[ import mx.controls.Alert; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; [bindable] var id1:String = "007"; [bindable] var email1:String = "@"; [bindable] var date1:String = "2000-1-1"; protected function button1_clickHandler(event:MouseEvent):void { /** * 1.将参数封装成Object对象 2.将Object对象转换成json串 3.将json赋值给参数 4.传递参数 */ var user:Object = {}; user.id = num.text; user.email = email.text; user.date = date.text; var jsonStr:String = JSON.stringify(user); var params:URLVariables = new URLVariables(); params.user = jsonStr; http.send(params); } /** * 获取后端传过来的json对象并进行解析 */ protected function http_resultHandler(event:ResultEvent):void { var user:Object = JSON.parse(event.result.toString()); java_id.text = user.id; java_email.text = user.email; java_date.text = user.date; } protected function http_faultHandler(event:FaultEvent):void { Alert.show("error"); } ]]> </fx:Script> <fx:Declarations> <s:HTTPService id="http" method="POST" useProxy="false" showBusyCursor="true" resultFormat="e4x" url="http://localhost:8080/test/RegistAction" result="http_resultHandler(event)" fault="http_faultHandler(event)" /> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <s:Label x="152" y="71" height="22" text="员工编号"/> <s:Label x="152" y="108" height="22" text="邮 箱"/> <s:TextInput id="num" text="{id1}" x="220" y="71"/> <s:TextInput id="email" text="{email1}" x="220" y="108"/> <s:Label x="151" y="145" height="22" text="注册日期"/> <s:TextInput id="date" text="{date1}" x="219" y="145"/> <s:Button x="151" y="185" width="236" height="27" label="注 册" chromeColor="#1747F8" click="button1_clickHandler(event)"/> <s:TextInput id="java_id" x="515" y="69"/> <s:TextInput id="java_date" x="515" y="150"/> <s:TextInput id="java_email" x="515" y="108"/> <s:Label x="423" y="78" text="员工编号:"/> <s:Label x="427" y="160" text="注册日期:"/> <s:Label x="427" y="115" text="邮 箱:"/> <s:Label x="476" y="193" width="161" height="34" text="后端传输数据展示区"/> </s:Application> <!-- 二、 Java 封装/发送、接收/解析 Json --> protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { /** * 1.从flex前端接收json串 2.将json串 转换为jsonObject 3.将jsonObject转换为JavaBean */ String jsonStr = request.getParameter("user"); JSONObject jo = JSONObject.fromObject(jsonStr); UserEntry user = new UserEntry(); user.setId((String) jo.get("id")); user.setEmail((String) jo.get("email")); String dateStr = (String) jo.get("date"); Date dateObj = Date.valueOf(dateStr); user.setDate(dateObj); /** * 1.将use 4000 r对象封装成json对象 2.json对象 将传递给Flex */ JSONObject resultJO = new JSONObject(); dateStr = user.getDate().toString(); resultJO.put("id", user.getId()); resultJO.put("email", user.getEmail()); resultJO.put("date",dateStr); PrintWriter out = response.getWriter(); out.print(resultJO); }
相关文章推荐
- Flex与Java通信之HttpService方式
- flex与java通信三:httpService
- Flex与Java通信之HttpService
- Flex与Java通信之HttpService方式
- flex通过HTTPService与java通信例子
- Flex中HTTPService与java后台通信
- Flex Httpservice和java后台通信传值出现中文乱码
- Java与Flex学习笔记(5)----Flex与Java通信之HttpService方式
- Flex httpservice 和java struts2 通信 地址提交中文乱码解决方法
- flex基础篇一,基于httpservice通信+java后台的项目创建
- flex中httpservice与java后台交互的两种传值方式
- Flex的通信方式(四)——HTTPService_2
- flex中httpservice与java后台交互的两种传值方式
- flex的httpservice与java交互过程中的乱码问题
- flex学习笔记6-----数据通信HTTPService
- Flex 与外部的数据通信(HTTPService,URLLoader和URLRequest)
- flex httpservice与java通讯的中文乱码解决。
- Flex中使用HttpService和WebService方式通信
- Flex中使用HttpService和WebService方式通信
- flex php httpservice通信简单例子