<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    瘋狂

    STANDING ON THE SHOULDERS OF GIANTS
    posts - 481, comments - 486, trackbacks - 0, articles - 1
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    使用BlazeDS實現Java和Flex通信(轉載)

    Posted on 2010-01-13 17:22 瘋狂 閱讀(9891) 評論(2)  編輯  收藏 所屬分類: flex
    world
    轉載地址:http://www.yeeach.com/2009/07/21/%e4%bd%bf%e7%94%a8blazeds%e5%ae%9e%e7%8e%b0java%e5%92%8cflex%e9%80%9a%e4%bf%a1%e4%b9%8bhello-world/

    新的項目對用戶體驗及用戶互動要求較高,決定選用Flex作為前端的展現技術,整體框架仍然是Flex+Spring+Hibernate(考慮采用seam中)。作為入門,先從經典的Hello world開始,暫時不考慮Flex與Spring、Hibernate的集成。

    Flex要實現與Java集成,開源項目BlazeDSGraniteDSFlamingo都提供了相應的解決方案,考慮到BlazeDS是Adobe官方的開源項目,因此采用BlazeDs作為Flex與Java通信的基礎框架。什么是BlazeDS呢,看看官方的介紹:

    BlazeDS is the server-based Java remoting and web messaging technology that enables developers to easily connect to back-end distributed data and push data in real-time to Adobe® Flex® and Adobe AIR™ applications for more responsive rich Internet application (RIA) experiences.

    開發工具采用Eclipse+Flex Builder 3 Plug-in方式,不采用Flex Builder 3。先安裝Eclipse,再安裝Flex Builder 3 Plug-in,相關的安裝配置不再贅述。

    1、下載BlazeDS

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

    由于BlazeDS Turnkey中包含BlazeDS的使用例子,對于入門熟悉Flex及BlazeDS都有較好的參考價值,因此建議下載BlazeDS Turnkey。

    關于blazeds-turnkey 的目錄說明:

    docs:BlazeDS Javadoc

    resources:BlazeDS的相關支持包,包括clustering(采用jgroups)、BlazeDS與ColdFusion 集成的配置文件、BlazeDS的配置文件、BlazeDS與AJAX集成的橋、Flex的SDK、Flex的java library、BlazeDS與Tomcat、Jboss、Websphere等security集成的支持包。

    sampledb:hsqldb的啟動腳本及樣例數據庫

    tomcat:Tomcat 包

    blazeds.war:最小化的BlazeDS 文件,可以作為空白項目來建立BlazeDS 應用程序。

    sample.war:BlazeDS的demo例子(所謂的testdrive)。

    ds-console.war :BlazeDS的部署管理程序。

    2、建立Java Web Project

    File->New->Web Project 建立Java helloworld項目

    blazeds1 在helloworld/src下,新建com.yeeach.HelloWorldService類,內容如下:

    package com.yeeach;

    public class HelloWorldService {
    public String hello(String var1) {
    return “hello ” + var1;
    }
    public String world(String var1) {
    return “world ” + var1;
    }
    }

    3、建立helloworld的BlazeDS開發環境

    3.1、拷貝blazeds.war下的WEB-INF到helloworld的目錄下,覆蓋原有的WEB-INF

    3.2、在helloworld下建立flex-src目錄(與src同級),用于存放flex的相關代碼

    blazeds2 helloworld/src:用于存放項目的java代碼

    helloworld/flex-src:用于存放項目flex的相關代碼

    helloworld/WebRoot/WEB-INF/flex:存放flex的相關配置文件

    3.3、設置Flex Project Nature

    blazeds3

    blazeds4

    blazeds5

    3.4、在helloworld/flex-src下,新建MXML Application :helloworld.mxml  ,內容如下:

    <?xml version=”1.0″ encoding=”utf-8″?>
    <mx:Application xmlns:mx=”
    http://www.adobe.com/2006/mxml”
    layout=”vertical”>
    <mx:RemoteObject destination=”com.yeeach.HelloWorldService”
    id=”helloWorldService”>
    <mx:method name=”hello”
    result=”sayHelloResult(event)”/>
    <mx:method name=”world”
    result=”sayWorldResult(event)”/>
    </mx:RemoteObject>
    <mx:HBox>
    <mx:Label text=”輸入:”/>
    <mx:TextInput id=”inputStr”/>
    <mx:Button label=”say hello”
    click=”sayHello(event);”/>
    <mx:Button label=”say world”
    click=”sayWorld(event);”/>
    </mx:HBox>
    <mx:HBox>
    <mx:Label text=”結果:”/>
    <mx:TextArea id=”result”/>
    </mx:HBox>

    <mx:Script>

    <![CDATA[
    import mx.rpc.events.FaultEvent;
    import mx.controls.Alert;
    import mx.rpc.events.ResultEvent;

    function sayHello(event:Event):void
    {
    var inputVar:String=inputStr.text;
    helloWorldService.hello(inputVar);

    }

    function sayWorld(event:Event):void
    {
    var inputVar:String=inputStr.text;
    helloWorldService.world(inputVar);

    }

    private function sayHelloResult(event:ResultEvent):void
    {
    result.text=event.result.toString();
    Alert.show(event.result.toString(), "返回結果");
    }

    private function sayWorldResult(event:ResultEvent):void
    {
    result.text=event.result.toString();
    Alert.show(event.result.toString(), "返回結果");
    }
    ]]>
    </mx:Script>
    </mx:Application>

    3.5、修改remoting-config.xml,增加對destination的說明

    <destination id=”com.yeeach.HelloWorldService”>
    <properties>
    <source>com.yeeach.HelloWorldService</source>
    </properties>
    </destination>

    3.6、設置Flex Build Path等相關屬性

    1)右鍵->Properties,設置Flex Build Path屬性,將Main source folder修改為flex-src,然后點擊“OK”

    2)右鍵->Properties,設置Flex Applications屬性,添加flex-src下的其他Application,然后點擊“OK”

    如果需要添加flex-src子目錄下的其他Application(例如helloworld/flex-src/com/yeeach/helloworld1.mxml),目前從UI界面似乎無法正確添加,可以直接修改.actionScriptProperties,在<applications></applications>中間增加相應的Application

    <applications>
    <application path=”helloworld.mxml”/>

    <application path=”com/yeeach.com/helloworld1.mxml”/>
    </applications>

    3)右鍵->Properties,設置Flex Compiler屬性,將Flex SDK version 修改為“Use default”或“Use a specific SDK”,指向正確的Flex SDK;確認“Additional compiler arguments”配置參數正確,然后點擊“OK”

    blazeds6 4)右鍵->Properties,設置Flex Server屬性,配置為正確的參數,然后點擊“OK”

    blazeds7

    3.7、部署helloworld 應用到Tomcat

    通過http://127.0.0.1:8080/helloworld/helloworld.swf來訪問我們的hello world

    3.8、分析helloworld.mxml

    <?xml version=”1.0″ encoding=”utf-8″?>
    <mx:Application xmlns:mx=”
    http://www.adobe.com/2006/mxml”
    layout=”vertical”>
    <mx:RemoteObject destination=”com.yeeach.HelloWorldService”
    id=”helloWorldService”>

    //此處的destination=”com.yeeach.HelloWorldService”與remoting-config.xml中的id=”com.yeeach.HelloWorldService”完全匹配

    //id=”helloWorldService”用來在actionscript中標識destination=”com.yeeach.HelloWorldService”,后面的helloWorldService.hello(inputVar)等都使用此id;

    <mx:method name=”hello”
    result=”sayHelloResult(event)”/>

    //mx:method 聲明java類com.yeeah.com.HelloWorldService中的hello方法及響應結果回調函數sayHelloResult
    <mx:method name=”world”
    result=”sayWorldResult(event)”/>
    </mx:RemoteObject>
    <mx:HBox>
    <mx:Label text=”輸入:”/>
    <mx:TextInput id=”inputStr”/>
    <mx:Button label=”say hello”
    click=”sayHello(event);”/>
    <mx:Button label=”say world”
    click=”sayWorld(event);”/>
    </mx:HBox>
    <mx:HBox>
    <mx:Label text=”結果:”/>
    <mx:TextArea id=”result”/>
    </mx:HBox>

    <mx:Script>

    <![CDATA[
    import mx.rpc.events.FaultEvent;
    import mx.controls.Alert;
    import mx.rpc.events.ResultEvent;

    function sayHello(event:Event):void
    {
    var inputVar:String=inputStr.text;
    helloWorldService.hello(inputVar);

    }

    function sayWorld(event:Event):void
    {
    var inputVar:String=inputStr.text;
    helloWorldService.world(inputVar);

    }

    private function sayHelloResult(event:ResultEvent):void
    {
    result.text=event.result.toString();
    Alert.show(event.result.toString(), "返回結果");
    }

    private function sayWorldResult(event:ResultEvent):void
    {
    result.text=event.result.toString();
    Alert.show(event.result.toString(), "返回結果");
    }
    ]]>
    </mx:Script>
    </mx:Application>

    代碼文件:helloworld.rar


    評論

    # re: 使用BlazeDS實現Java和Flex通信(轉載)[未登錄]  回復  更多評論   

    2014-01-22 12:07 by 1
    1

    # re: 使用BlazeDS實現Java和Flex通信(轉載)[未登錄]  回復  更多評論   

    2014-03-17 16:00 by a
    a
    主站蜘蛛池模板: 69成人免费视频无码专区| 久久久久成人片免费观看蜜芽| 欧美男同gv免费网站观看| 亚洲日本乱码一区二区在线二产线| 免费播放在线日本感人片| 亚洲另类激情综合偷自拍图| 国产精品免费视频观看拍拍| 亚洲国产中文字幕在线观看| 亚欧乱色国产精品免费视频| 亚洲视频在线一区二区| 黄色网址免费在线观看| 亚洲人成人一区二区三区| 中文字幕免费观看视频| 亚洲精品综合一二三区在线 | 亚洲中文字幕无码爆乳av中文 | 十八禁无码免费网站| 亚洲成人午夜电影| 无码人妻一区二区三区免费 | 亚洲国产精品福利片在线观看| a级黄色毛片免费播放视频| 亚洲人成在线观看| 成人毛片免费观看视频| 性生大片视频免费观看一级| 久久精品国产亚洲沈樵| 亚洲视频免费在线看| 在线91精品亚洲网站精品成人| 狠狠亚洲婷婷综合色香五月排名| 日本一卡精品视频免费 | 亚洲精品黄色视频在线观看免费资源 | 最新亚洲精品国偷自产在线| 国产高清免费在线| 99久久精品毛片免费播放| 亚洲日本国产精华液| 免费成人黄色大片| 99ee6热久久免费精品6| 婷婷亚洲综合五月天小说在线| 亚洲桃色AV无码| 噼里啪啦电影在线观看免费高清| 麻豆69堂免费视频| 亚洲精品美女久久久久9999| 免费永久看黄在线观看app|