NetBeans 的restful與flex互動

來源:互聯網
上載者:User

一、:1、先開啟你的netbeans IDE,選擇建立java web的wed application(next)

         2、寫入你的工程名字並選擇路徑(next)

         3、java ee版本選擇java ee5(finish)

         4、以上完成後就單擊右鍵(projectname)建立基於模式REST風格的web........,選擇簡單,單擊next把MIME中

改為text/plain.(finish)

 

 

二、下載一個(blazeds.rar)解壓:

                地址:百度一下就OK

把解壓後的檔案複製到你netbeans工程中的WEB_INF中。修改lib中的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>
        <destination id="helloWorld">
            <properties>
                <source>com.ws.HelloWorlds</source>
            </properties>
</service>

 

三、再在NetBeans工程中建一個類:HelloWorlds代碼如下:

 public HelloWorlds(){
    }
    public String getHelloWorld(String name){
        return "Hello "+name;
    }
    public String validatePassword(String name,String password){
        return null;
    }

 

四、接下來就開啟FlexBudler:

建立工程代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 <mx:RemoteObject id="say" destination="helloWorld">
  
 </mx:RemoteObject>
 <mx:Button x="10" y="48" label="click" click="remotingSayHello(event)"/>
 <mx:TextInput x="60" y="89" id="tiName"/>
 <mx:Label x="10" y="91" text="name:"/>
 <mx:Label x="259" y="91" text="{say.getHelloWorld.lastResult}" id="lblView" color="#FCEE09"/>
 <mx:Script>
  <![CDATA[
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
   public function remotingSayHello(event:Event):void{
    var iname:String=tiName.text;
    say.getHelloWorld(iname);
   }
  ]]>
 </mx:Script>
</mx:Application>

 

五、儲存並運行,點擊click。。。就OK啦。。

註:可能還不夠詳細,但是是可以看到簡單效果的。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.