flex与java通信一:RemoteObject
flex与java通信的三种方式: 1.通过httpService:你访问一个xml或者servlet,然后flex接收返回的xml数据 2.通过webService:你访问一个webService服务,然后获得文本信息 3.通过RemoteObject:可以通过blazeds来访问远程service接口方法,Flex接收一个对象。
一、按照百度文库里面的Myeclipse8.5+flex4.5+Blazeds+SSH tomcat.doc文件搭建了一个项目:这个项目是一个集成了flex和java的web项目。 下载地址:http://pan.baidu.com/s/1o68W8OE 下载下来后,导入到搭建好开发环境的IDE中,修改项目的属性:flex服务器等,右键“testFlex.mxml”即可运行。 一些关键点: 1、随便编写一个程序,如:
package com.biz; public final class UserBiz { public String test(String value){ return "Hello "+value; } }2、修改remoting-config.xml: <?xml version="1.0" encoding="UTF-8"?> <service id="remoting-service" class="flex.messaging.services.RemotingService"> <adapters> <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/> </adapters> <default-channels> <channel ref="my-amf" /> </default-channels> <destination id="findUser"> <properties> <source>com.biz.UserBiz</source> </properties> </destination> </service>3、在flex编写的界面文件中调用: <?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:Script> <![CDATA[ import mx.controls.Alert; import mx.rpc.events.ResultEvent; protected function findUser_resultHandler(event:ResultEvent):void { var re:String = event.result as String; Alert.show(re); } protected function button1_clickHandler(event:MouseEvent):void { findUser.test(txtName.text); } ]]> </fx:Script> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> <s:RemoteObject id="findUser" destination="findUser" result="findUser_resultHandler(event)"/> </fx:Declarations> <s:Panel width="458" height="289"> <s:TextInput id="txtName"/> <s:Button x="136" y="0" label="send" click="button1_clickHandler(event)"/> </s:Panel> </s:Application> 二、搭建的一个flex和java web项目分开的项目: ? ? ??下载地址:http://pan.baidu.com/s/1dDiQ7mD 同样的下载下来后需要进行依稀配置,适应本机开发环境,才能继续。 一些关键点:同上 4、flex编写的界面文件中s:RemoteObject略有不同:? <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> <s:RemoteObject id="findUser" destination="findUser" result="findUser_resultHandler(event)" fault="findUser_faultHandler(event)" endpoint="http://localhost:8080/java/messagebroker/amf"/> </fx:Declarations> --------------------------------------------------------------------------------------- 1、 <s:RemoteObject id="Service" destination="Service" endpoint="http://localhost:8080/aser/messagebroker/amf" requestTimeout="120"/> 2、 3、 <destination id="Service"> <properties> <source>Service</source> </properties> </destination> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |