[color=blue]请关注新浪微博 账号:屌丝开发控([url]http://weibo.com/u/3356934744[/url])[/color]
首先要搭建好开发环境,并且已经能发布、运行Web项目了
如果还没有,参见[url]http://quasimodo-es.iteye.com/admin/blogs/499584[/url]
配置Hello World
如新建的项目名为 TestLCDS
1、TestLCDS.mxml
2、WebRoot/WEB-INF/flex/remoting-config.xml
3、
运行项目,点击" hello java"Button ,在控制台就可以看到
打印出的
hello world , and hello java
分析一下控制台的输出,可以看到Flex和J2EE是怎么通信的:
[LCDS]Channel endpoint my-amf received request.
[LCDS]Deserializing AMF/HTTP request
Version: 3
(Message #0 targetURI=null, responseURI=/2)
(Array #0)
[0] = (Typed Object #0 'flex.messaging.messages.RemotingMessage')
operation = "sayHello"
source = null
body = (Array #1)
[0] = " java "
messageId = "7DB329E0-34BE-658E-5D84-82242C0DDD0A"
clientId = "21AEFB2F-101E-8EC5-A34B-86785A7ED457"
timeToLive = 0
timestamp = 0
destination = "HelloWorldRO"
headers = (Object #2)
DSId = "nil"
DSEndpoint = "my-amf"
hello world , and hello java
[LCDS]Adapter 'java-object' called 'com.Hello.sayHello(java.util.Arrays$ArrayList (Collection size:1)
[0] = java
)'
[LCDS]Result: 'null'
[LCDS]Serializing AMF/HTTP response
Version: 3
(Message #0 targetURI=/2/onResult, responseURI=)
(Externalizable Object #0 'DSK')
1.256313859132E12
(Byte Array #1, Length 16)
(Byte Array #2, Length 16)
(Byte Array #3, Length 16)
如果项目不能和J2EE通信,控制台没有显示通信信息,重新配置Flex Build path 和 Flex Server参数
[url]http://quasimodo-es.iteye.com/blog/486739[/url]
建议使用方法2
Flex 和 J2EE之间信息交互:Object 、 array ==
[url]http://quasimodo-es.iteye.com/blog/503830[/url]
首先要搭建好开发环境,并且已经能发布、运行Web项目了
如果还没有,参见[url]http://quasimodo-es.iteye.com/admin/blogs/499584[/url]
配置Hello World
如新建的项目名为 TestLCDS
1、TestLCDS.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:RemoteObject id="MyRO" destination="HelloWorldRO"/>
<mx:Script>
<![CDATA[
private function onClick() : void{
MyRO.sayHello(" java ");
}
]]>
</mx:Script>
<mx:Button x="220" y="91" label="hello java" click="onClick()"/>
</mx:Application>
2、WebRoot/WEB-INF/flex/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>
<!-- destinations -->
<destination id="HelloWorldRO">
<properties>
<source>com.Hello</source> <!-- Java类 -->
</properties>
</destination>
</service>
3、
package com;
public class Hello {
// 方法必须是public
public void sayHello(String str){
System.out.println(" hello world , and hello " + str);
}
}
运行项目,点击" hello java"Button ,在控制台就可以看到
打印出的
hello world , and hello java
分析一下控制台的输出,可以看到Flex和J2EE是怎么通信的:
[LCDS]Channel endpoint my-amf received request.
[LCDS]Deserializing AMF/HTTP request
Version: 3
(Message #0 targetURI=null, responseURI=/2)
(Array #0)
[0] = (Typed Object #0 'flex.messaging.messages.RemotingMessage')
operation = "sayHello"
source = null
body = (Array #1)
[0] = " java "
messageId = "7DB329E0-34BE-658E-5D84-82242C0DDD0A"
clientId = "21AEFB2F-101E-8EC5-A34B-86785A7ED457"
timeToLive = 0
timestamp = 0
destination = "HelloWorldRO"
headers = (Object #2)
DSId = "nil"
DSEndpoint = "my-amf"
hello world , and hello java
[LCDS]Adapter 'java-object' called 'com.Hello.sayHello(java.util.Arrays$ArrayList (Collection size:1)
[0] = java
)'
[LCDS]Result: 'null'
[LCDS]Serializing AMF/HTTP response
Version: 3
(Message #0 targetURI=/2/onResult, responseURI=)
(Externalizable Object #0 'DSK')
1.256313859132E12
(Byte Array #1, Length 16)
(Byte Array #2, Length 16)
(Byte Array #3, Length 16)
如果项目不能和J2EE通信,控制台没有显示通信信息,重新配置Flex Build path 和 Flex Server参数
[url]http://quasimodo-es.iteye.com/blog/486739[/url]
建议使用方法2
Flex 和 J2EE之间信息交互:Object 、 array ==
[url]http://quasimodo-es.iteye.com/blog/503830[/url]