flash player 支持一種協(xié)議 AMF(action message format),這是一個二進制格式的協(xié)議,能夠替代用于傳輸xml的基本的協(xié)議而在http協(xié)議之上的交換數(shù)據(jù)。
BalzeDs中包含了AMF的java實現(xiàn),可以用來與服務(wù)器的java對象遠程交互,也可以在客戶端傳遞信息。BalzeDs能在很多基于java服務(wù)器上工作(tomcat,websphere,weblogic,jboss)
簡單的說BlazeDs是一個基于服務(wù)器的java遠程調(diào)用和web消息傳遞技術(shù),它能夠讓后臺的java應(yīng)用程序和運行在瀏覽器的flex進行通信。
----------------------------------例子如下
1:打開myEclipes,新建一個項目remotejf, src下建包com.test和類HelloJavaFlex
public class HelloJavaFlex {
public String hello(String name) {
return "hello,"+name+"通信了 哈哈";
}
}
2: 下載blazeDs.war,用winrar打開,拷貝WEB-INF到remotejf的webroot下,覆蓋原來的WEB-INF
3:找到WEB-INF下的remoting-config.xml 增加destination
<?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="test">
<properties>
<source>com.test.HelloJavaFlex</source>
</properties>
</destination>
4 flash build下創(chuàng)建項目 testFlex, 打開testFlex.mxml
<?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 button1_clickHandler(event:MouseEvent):void
{
var nameText:String = textId.text;
remoteId.hello(nameText);
}
protected function remoteHello_resultHandler(event:ResultEvent):void
{
var name:String = event.result as String;
Alert.show(name);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 將非可視元素(例如服務(wù)、值對象)放在此處 -->
<s:RemoteObject id="remoteId" destination="test" result="remoteHello_resultHandler(event)" endpoint="http://localhost:8080/remotejf/messagebroker/amf">
</s:RemoteObject>
</fx:Declarations>
<s:Label x="228" y="134" text="姓名:" width="50" height="22"/>
<s:TextInput x="286" y="134" id="textId"/>
<s:Button x="286" y="206" label="jfbutton" width="74" click="button1_clickHandler(event)"/>
</s:Application>
5 啟動tomcat
6:運行testFlex.mxml
注意:按順序來啊