Flex3與BlazeDS HelloWorld 詳解

來源:互聯網
上載者:User

BlazeDS的下載和介紹:
http://opensource.adobe.com/wiki/display/blazeds/Release+Builds 
有Tomcat的下載 

http://flexorg.wip3.adobe.com/blazeds/3.0.x/milestone/3978/blazeds-bin-3.2.0.3978.zip

沒Tomcat的下載 

http://flexorg.wip3.adobe.com/blazeds/3.0.x/milestone/3978/blazeds-turnkey-3.2.0.3978.zip

下載後將blazeds.war部署到tomcat下即可。

Flex Builder外掛程式的安裝不再作介紹

開發工作為MyEclipse:

1.建立一個Flex工程

按照圖中進行配置
2.下一步:

指定已經下載的blazeds.war
3.下一步.

配置url
4.完成後右鍵配置工程屬性:

注意context的修改,不然運行程式會報404.

5.建立一個測試類別:

package com;public class HelloWorld{    public String say(String username)    {        System.out.println("hello");        return "你好!" + username;    }        public String login(String username,String password)    {        System.out.println("login");        if(username.equals("admin") && password.equals("admin"))        {            return "success";        }        else        {            return "failure";        }    }}

6.配置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>    <!-- 目標java類 -->    <destination id="helloworld">        <properties>            <source>com.HelloWorld</source>        </properties>    </destination>    </service>

7.編寫mxml檔案:

<?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;        import mx.controls.Alert;        //hello事件        private function helloClick():void        {            this.hello.say(this.username.text);        }                //登入事件         private function loginClick():void        {            this.login.login(this.username.text,this.password.text);        }        //處理hello事件 傳回值        private function resultHandler(e:ResultEvent):void        {            Alert.show(e.result.toString());        }        //處理登入事件傳回值        private function resultLoginHandler(e:ResultEvent):void        {            Alert.show(e.result as String);        }            ]]></mx:Script>            <!--遠程對象調用--><mx:RemoteObject id="hello" destination="helloworld" result="resultHandler(event)" />    <mx:RemoteObject id="login" destination="helloworld" result="resultLoginHandler(event)" />            <mx:TextInput id="username" x="187" y="99" width="119"/>    <mx:Label x="123" y="101" text="username:"/>    <mx:Label x="123" y="141" text="password:"/>    <mx:TextInput id="password" x="187" y="139" width="119" />        <mx:Button x="241" y="184" label="Login" click="loginClick()"/>    <mx:Button x="123" y="184" label="HelloWorld" click="helloClick()"/>        </mx:Application>

7.找到bin-debug下的secondBlaze.html右鍵選擇在Run on Server即可。

 效
源碼下載

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.