版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、flex4与Java交互 flex4出来一段时间了,去年看了一段时间flex3,后来由于暂时没有项目需求.所以flex遗忘了很多.这次使用flex4+myeclipse8.5录制了一个视频.以免时间长了遗忘. 软件环境:windows7+flex4+myeclipse8.5+blazeds 功能描述:分别用代码实现
2、了三种flex4与Java通信 三种方式: 1 flex 与普通java类通信RemoteObject
3、 2 flex 与服务器交互HTTPService 3 flex与webservice交互WebService &
4、#160; flex 与普通java类通信RemoteObject 普通Java类: package com.flex.demo;/* */* * 功能描述:该类用来实现flex与普通java类中的方法通信 * author Administrator * */public class&
5、#160;SimpleService public String sayHello(String name) return "Hello, "+name; 配置说明:配置remoting-config.xml<destinatio
6、n id="myservice"> <properties> <source>com.flex.demo.SimpleService</source> </properties>
7、0; </destination> 调用<!-flex 与普通java类通信-> <s:RemoteObject id="serv" destination="myservice" fault="serv_faultHandler(event)"&
8、#160;result="serv_resultHandler(event)"> </s:RemoteObject> flex 与服务器交互HTTPService
9、0; servlet代码 package com.flex.demo;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.Ht
10、tpServletResponse;/* */* * 功能描述:该servlet用来与flex进行交互 * author Administrator * */SuppressWarnings("serial")public class SimpleServiceServlet extends HttpServlet Override
11、0; protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException request.s
12、etCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); response.getWriter().write("我是服务器");
13、0;调用<!- flex 与服务器交互-> <s:HTTPService id="service" fault="service_faultHandler(event)" result="service_resultHandler(event)" url="http:/localhost:8080/flexdemo/simpleServiceServlet
14、"> </s:HTTPService> flex与webservice交互WebService<!-flex与webservice交互这里调用一个天气预报的webservice->
15、 <s:WebService id="ws" wsdl="
16、0; fault="ws_faultHandler(event)" result="ws_resultHandler(event)"
17、 showBusyCursor="true"> <!- 第二种调用webservice的方法<s:operation>-> &
18、#160; <!- <s:operation name="getWeatherbyCityName"> webservice中的方法名-> <s:operation name="getWeatherbyCityName"> &
19、#160; <!-传递的参数-> <s:request>
20、0; <!-参数名称必须与webservice中定义的参数名一致否则调用不成功报错-> <theCityName>
21、; city.text </theCityName> </s:reque
22、st> </s:operation> </s:WebService> 三种方式完整的配置例子&l
23、t;?xml version="1.0" encoding="utf-8"?><s:Application xmlns:fx=" xmlns:s="library:/
24、; xmlns:mx="library:/ creationComplete="service.send()" > <fx:Scrip
25、t> <!CDATA import mx.controls.Alert; import mx.rpc.events.FaultEvent;
26、160; import mx.rpc.events.ResultEvent; /错误处理函数 protected function serv_faultHandler(event:FaultEvent):
27、void Alert.show("调用失败了:"+event.fault.message as String,"提示");
28、 /成功调用函数 protected function serv_resultHandler(event:ResultEvent):void
29、 Alert.show("调用成功了:"+event.result as String,"提示");
30、; protected function service_faultHandler(event:FaultEvent):void Alert.show("
31、调用失败了:"+event.fault.message as String,"提示"); protected function service_resultHandler(event:ResultEvent):void &
32、#160; Alert.show("调用成功了:"+event.result as String,"提示");
33、 protected function ws_faultHandler(event:FaultEvent):void
34、; Alert.show("调用失败了:"+event.fault.message as String,"提示");
35、60; /调用成功了 protected function ws_resultHandler(event:ResultEvent):void
36、 trace(event.result); lbl.text=(String)(event.result);
37、160; /第一种调用webservice的方法 /此方法调用webservice protected function btn_clickHandler(event:MouseEvent):void &
38、#160; /ws.getWeatherbyCityName(city.text); /第二中调用webservice的方法
39、 ws.getWeatherbyCityName.send();
40、; > </fx:Script> <fx:Declarations> <!- 将非可视元素(例如服务、值对象)放在此处 -> &
41、#160; <!-flex 与普通java类通信-> <s:RemoteObject id="serv" destination="myservice" fault="serv_faultHandler(event)" result="serv_resultHa
42、ndler(event)"> </s:RemoteObject> <!- flex 与服务器交互->
43、 <s:HTTPService id="service" fault="service_faultHandler(event)" result="service_resultHandler(event)" url="http:/localhost:8080/flexdemo/simpleServiceServlet">
44、60; </s:HTTPService> <!-flex与webservice交互这里调用一个天气预报的webservice->
45、0;<s:WebService id="ws" wsdl="
46、160; fault="ws_faultHandler(event)" result="ws_resultHandler(event)"
47、0; showBusyCursor="true"> <!- 第二种调用webservice的方法<s:operation>->
48、; <!- <s:operation name="getWeatherbyCityName"> webservice中的方法名-> <s:operation name="getWeatherbyCityName">
49、; <!-传递的参数-> <s:request> <!-参数名称必须与webservice中定义的参数名一致否则调用不成功报错->
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 陇南市辅警招聘考试题及答案
- 2026年盆腔淤血症合并肠病诊疗试题及答案(消化内科版)
- 滑膜液标本异常护理查房
- 带动收购合同
- 2026年河北省廊坊市事业单位工勤技能考试题库(含答案)
- 山西省晋中市2025-2026学年高一下学期素养测评(二)数学试卷(含答案)
- 《婴幼儿学习与发展》课件-2.第二节:婴幼儿学习与发展的关系和研究意义
- 2026六年级上《分数乘法》同步练习
- 2026年挫折教育指导课程
- 易爆物品储存库安全管理办法
- 墙纸墙布装饰施工工艺流程
- 施工机械设备配置方案
- 《建筑工程施工许可管理办法》2021年9月28日修订
- 深圳益电通变频器说明书TD90
- 人教版九年级物理 15.3串联和并联(学习、上课课件)
- DLT 572-2021 电力变压器运行规程
- ekf艾柯夫sl750采煤机中文操作手册
- 中英对照版-中文版-The-Dead-By-James-Joyces死者-詹姆斯-乔伊斯
- 初中数学-专项24 圆内最大张角米勒角问题
- DB11T 1211-2023 中央空调系统运行节能监测
- 钢铁是怎样炼成的人物形象分析课件
评论
0/150
提交评论