我的漫漫程序之旅

          專注于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工程

          按照圖中進行配置
          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>
              
          <!-- 目標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>    
              
              
          <!--遠程對象調(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)航:
           
          主站蜘蛛池模板: 乐亭县| 肃北| 酒泉市| 于都县| 昌邑市| 宁海县| 教育| 绥宁县| 中西区| 高邮市| 廉江市| 右玉县| 威海市| 成武县| 东山县| 贵溪市| 龙井市| 泰州市| 前郭尔| 彰化市| 萨迦县| 湘阴县| 呼伦贝尔市| 建阳市| 新和县| 襄城县| 台北县| 中牟县| 武威市| 绍兴县| 南溪县| 迁西县| 广德县| 定安县| 碌曲县| 五常市| 怀安县| 乌拉特前旗| 上饶市| 长岛县| 青阳县|