Next
我們可以在WEB-INFO/flex下找到一個remoting-config.xml。若要連到後端,必須在remoting-config.xml裡做些設定,如何設定?等下後面會介紹。
2. 寫個簡單的java程式
(1) 在src下建一個java檔
(2) 寫一個簡單的方法 - 處理和回傳flex傳過來的字串
3. 設定remoting-config.xml
package com;
public class RemoteObject_Test {
public String sayHello(String s){
return "Hello~ "+s;
}
}
在remoting-config.xml的service裡新增一段tag
<destination id="Test">
<properties>
<source>com.RemoteObject_Test</source>
</properties>
</destination>
tag destination是搭配RemoteObject的屬性(destination)。屬性id為destination的目標
4. 測試的介面
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
public function connectJavaBean():void{
ro.sayHello(input.text);
}
public function connResult(event:ResultEvent):void{
Alert.show(event.result as String,"Message");
}
public function connFault(event:FaultEvent):void{
Alert.show(event.fault.message,"Error");
}
]]>
</mx:Script>
<mx:RemoteObject id="ro" destination="Test"
result="connResult(event)" fault="connFault(event)"/>
<mx:HBox>
<mx:Label text="Your name is :"/>
<mx:TextInput id="input"/>
</mx:HBox>
<mx:Button label="Connect" click="connectJavaBean()"/>
</mx:Application>
5. 執行 (選擇Run on server)
(1) 執行畫面
(2) 執行結果
1 意見:
請教版主,參照您這個範例測試BlazeDS,卻發現Java回傳值是亂碼,不知是哪邊的參數沒設定正確嗎?
張貼留言