[RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error NetC

[RPC Fault faultString="Send failed"faultCode="Client.Error.MessageSend"faultDetail="Channel.Connect.Failed error NetConnection.Call.Failed:HTTP: Status 404:
url: 'http://localhost:8080/WebRoot/messagebroker/amf'"]

当我看到url时发现工程名是'FirstFlex',但信息提示成了WebRoot,故在工程属性对话框-->Flex Server中的
Root   Url    -->http://localhost:8080/FirstFlex
Context Root-->WebRoot 故把WebRoot改成'FirstFlex',重新编译运行即可。
原因是myeclipse没有把用户某些设置更新过去。

 

学学Flex与Java的交互:

(1)创建Java文件。点击src文件夹,然后创建java class.类的包为hello,名字为HelloWorld.
package hello;
 public class HelloWorld {
public String sayHelloTo(String str) {
System.out.println("Hello " + str);    
     return "Hello " + str; }    
}
(2)在FirstFlex.mxml文件中新建一个text和一个按钮,来显示从HelloWorld传回来的信息。
<?xml version="1.0" encoding="utf-8"?>
 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
 <mx:Script>
  <![CDATA[ import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
       [Bindable]
       private var helloResult:String;
       private function sayHelloTo():void {
         ro.sayHelloTo(inputText.text);
         }
        private function resultHandler(event:ResultEvent):void {
           helloResult = event.result as String;
              } ]]> </mx:Script>
         <mx:RemoteObject id="ro" destination="helloworld" result="resultHandler(event)" />
          <mx:HBox width="100%">
            <mx:TextInput id="inputText"/>
            <mx:Button label="Submit" click="sayHelloTo()"/>
         </mx:HBox>
        <mx:Label text="{helloResult}"  x="10" y="30"/>
     </mx:Application>

(3)现在,我们要定义remote object,让flex程序能够调用java类。首先来配置/WEB-INF/flex/remoting-config.xml文件,添加以下粗体部分来新增一个destionation—HelloWorld类。
<?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>hello.HelloWorld</source>
        </properties>
  </destination>
</service>

(4)到此,配置结束。然后选择此项目,选择在服务器上执行。即浏览地址为:http://localhost:8080/FirstFlex/FirstFlex.html如果你能在输入框输入字段之后,点击按钮能返回Hello,XXX的信息,就代表成功了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值