我的漫漫程序之旅

          專注于JavaWeb開發(fā)
          隨筆 - 39, 文章 - 310, 評論 - 411, 引用 - 0
          數(shù)據(jù)加載中……

          Flex3與BlazeDS HelloWorld 詳解

          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插件的安裝不再作介紹

          開發(fā)工作為MyEclipse:

          1.新建一個Flex工程

          按照圖中進(jìn)行配置
          2.下一步:

          指定已經(jīng)下載的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>
              
          <!-- 目標(biāo)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>    
              
              
          <!--遠(yuǎn)程對象調(diào)用-->
          <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即可。
           效效果圖
          源碼下載

          posted on 2009-04-23 11:48 々上善若水々 閱讀(2675) 評論(3)  編輯  收藏

          評論

          # re: Flex3與BlazeDS HelloWorld 詳解  回復(fù)  更多評論   

          如果想做成兩個工程請參考:
          http://blog.sina.com.cn/s/blog_3ecb9b110100b2qu.html
          2009-04-23 11:49 | 々上善若水々

          # re: Flex3與BlazeDS HelloWorld 詳解  回復(fù)  更多評論   

          沒啥特別的啊,我以為有更好的重合地方,你可以看看spring有個集成方案!!!
          2009-04-24 23:20 | sdfasd

          # re: Flex3與BlazeDS HelloWorld 詳解  回復(fù)  更多評論   

          最代碼轉(zhuǎn)載地址:
          Flex3與java BlazeDS入門教程及其配置詳解 http://www.zuidaima.com/share/1789445387160576.htm
          2014-04-21 13:50 | 最代碼

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 平邑县| 长乐市| 杭锦后旗| 平遥县| 合山市| 五原县| 墨玉县| 白水县| 宣汉县| 明光市| 邛崃市| 通化县| 肥西县| 温州市| 南江县| 乌鲁木齐市| 澄江县| 榆林市| 拉萨市| 瓮安县| 娄底市| 万山特区| 疏附县| 油尖旺区| 临安市| 隆尧县| 阿克苏市| 和静县| 广河县| 阳春市| 于都县| 神池县| 神农架林区| 衡东县| 渭南市| 云和县| 洪江市| 永平县| 静宁县| 句容市| 新宁县|