网上有很多类似文章,但看完还是不够清晰,整理下网上的相关资料,自己试着搭建开发环境。
1下载软件:
eclipse-jee-ganymede-SR1-win32.zip
FB3_WWEJ_Plugin.exe
blazeds-turnkey-3.2.0.3978.zip
2建立动态web工程,名字就叫web
Finished
建立如下测试类
packagecn.test;
publicclassFlexTest{
publicStringgetName(Stringname){
System.out.println("Hello : "+name);
return"Hello : "+name;
}
}
把blazeds的WEB-INF下的lib,web.xml,flex拷贝到当前web工程的WEB-INF下覆盖
配置下web-inf/flex/的remote-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="flexTest">
<properties>
<source>cn.test.FlexTest</source>
</properties>
</destination>
</service>
增加Flex支持
当出现错误时候,修改Flex SDK为3.2
贴入下面代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
privatefunction sendData() : void{
test.getName(input.text);
}
privatefunction resultInfo(event:ResultEvent) : void {
message.text = event.result as String;
}
]]>
</mx:Script>
<mx:RemoteObject id="test" destination="flexTest"
result="resultInfo(event)" endpoint="/FlexWeb/messagebroker/amf" >
</mx:RemoteObject>
<mx:Label x="102" y="138" text="Name:"/>
<mx:TextInput id="input" x="152" y="136"/>
<mx:Button x="152" y="166" label="OK" click="sendData()"/>
<mx:Text id="message" x="219" y="218" text=""/>
<mx:Label x="152" y="218" text="Message:"/>
</mx:Application>
粗红地方需要注意
运行即可看到