`
wangyisong
  • 浏览: 236141 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

跟我StepByStep学FLEX教程------Demo11之HelloJavaFlex

    博客分类:
  • FLEX
 
阅读更多

跟我StepByStep学FLEX教程------Demo11之HelloJavaFlex 

 

说明:该文系作者原创,请勿商用或者用于论文发表,转载必须经作者同意并且注明出处。

 

      这一讲接上一讲讲述,所以阅读本讲之前一定要看上一讲每一步。

      新建一个Java类,切换到Java开发模式:


     呵呵,是不是很方便,Java就Java,Flex就Flex,都在myeclipse中切换模式就完成了。

     1、新建HelloJavaFlex.java,如下(目录在src下的com.test):

      package com.test;

/**
 * @author Wang YiSong
 * @version $Revision: $, $Date: $
 */
public class HelloJavaFlex {
 
 public String helloJavaFlex(String name) {
  System.out.println("哈哈,JAVA和FLEX可以通信了!");
  
  return "Hello,'" + name + "':JAVA和FLEX可以通信了";    
 }
}
      2、在WebRoot目录下的WEB-INF目录下自动生成的remoting-config.xml中增加如下配置:

<destination id="helloJavaFlex">
     <properties><source>com.test.HelloJavaFlex</source></properties>
    </destination>

     3、HelloFlexPro.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;

  public function remotingHelloJavaFlex():void{
   var logNam: String = namInputTxt.text;
   remoteHello.helloJavaFlex(logNam);
   remoteHello.addEventListener(ResultEvent.RESULT, getRoHelloRes);
  }
  
  private function getRoHelloRes(e: ResultEvent) :void {
   Alert.show(e.result.toString());
  }

 ]]>
 </mx:Script>
 <mx:RemoteObject destination="helloJavaFlex" id="remoteHello"></mx:RemoteObject>
 
 <mx:Button label="JAVA+FLEX通信" click="remotingHelloJavaFlex();" x="121" y="96" fontSize="12" width="209"/>
 <mx:Label text="姓名:" x="121" y="55" fontSize="12"/>
 <mx:TextInput id="namInputTxt" x="170" y="55"/> 
</mx:Application>

      启动Tomcat,运行效果如下:




      下一讲简单对该Demo进行解析。
 


 

 

 

 

  • 大小: 11 KB
  • 大小: 24.4 KB
  • 大小: 3.4 KB
分享到:
评论
7 楼 catlovefox 2010-04-22  
catlovefox 写道
QQ87465335 写道
我怎么没有数据返回呀,tomcat也没有报错。

因为你.java文件,放的位置,程序没找到~~~~~~
还是因为你配置的原因吧。
你也可以,把类和.mxml文件放在一个src下,试试~~~

说错了,
.java文件,要放在src下边。不是跟.mxml文件一个得flex_src.
你检查下你的{context.root}吧。
6 楼 catlovefox 2010-04-20  
QQ87465335 写道
我怎么没有数据返回呀,tomcat也没有报错。

因为你.java文件,放的位置,程序没找到~~~~~~
还是因为你配置的原因吧。
你也可以,把类和.mxml文件放在一个src下,试试~~~
5 楼 zsq007 2010-03-15  
为什么用myeclipse呢!~ 哎!~ eclipse 配置出错!~ 查找中!~!~ 
4 楼 lichuhui 2009-11-19  
总算解决了问题:
在上一篇文章的评论中我说道
引用
发现我的MyEclipse 7.5下,Flex服务器配置的界面跟楼主最后一张图中的不一样,并且文本框是Disabled的,不能配置

不知道是不是版本原因,无法从属性配置中做修改,导致出以下错误
引用
[RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed: url: 'http://localhost:8080/WebRoot/messagebroker/amf'"]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:290]
at mx.rpc::Responder/fault()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:58]
at mx.rpc::AsyncRequest/fault()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:103]
at mx.messaging::ChannelSet/faultPendingSends()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:1446]
at mx.messaging::ChannelSet/channelFaultHandler()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:1056]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.messaging::Channel/connectFailed()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\mx\messaging\Channel.as:1069]
at mx.messaging.channels::PollingChannel/connectFailed()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\mx\messaging\channels\PollingChannel.as:388]
at mx.messaging.channels::AMFChannel/statusHandler()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\mx\messaging\channels\AMFC

以上错误中可以看到这样的路径http://localhost:8080/WebRoot/messagebroker/amf,这其中的WebRoot明显跟我们的项目名称不一致,最后发现把WebRoot/WEB-INF/flex/services-config.xml中的{context.root}全改成项目名字就可以了,如下:
引用

<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://{server.name}:{server.port}/HelloFlex/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
        </channel-definition>

        <channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
            <endpoint url="https://{server.name}:{server.port}/HelloFlex/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
            <properties>
                <add-no-cache-headers>false</add-no-cache-headers>
            </properties>
        </channel-definition>

        <channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://{server.name}:{server.port}/HelloFlex/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
            <properties>
                <polling-enabled>true</polling-enabled>
                <polling-interval-seconds>4</polling-interval-seconds>
            </properties>
        </channel-definition>
3 楼 lichuhui 2009-11-19  
我的程序报错,请问楼主是什么原因呢?
引用
[RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed: url: 'http://localhost:8080/WebRoot/messagebroker/amf'"]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:290]
at mx.rpc::Responder/fault()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:58]
at mx.rpc::AsyncRequest/fault()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:103]
at mx.messaging::ChannelSet/faultPendingSends()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:1446]
at mx.messaging::ChannelSet/channelFaultHandler()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:1056]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.messaging::Channel/connectFailed()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\mx\messaging\Channel.as:1069]
at mx.messaging.channels::PollingChannel/connectFailed()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\mx\messaging\channels\PollingChannel.as:388]
at mx.messaging.channels::AMFChannel/statusHandler()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\mx\messaging\channels\AMFChannel.as:411]
2 楼 lichuhui 2009-11-19  
引用
2、在WebRoot目录下的WEB-INF目录下自动生成的remoting-config.xml中增加如下配置:

楼主,为什么我的remoting-config.xml是在WebRoot/WEB-INF/flex/remoting-config.xml下呢?
1 楼 QQ87465335 2009-11-10  
我怎么没有数据返回呀,tomcat也没有报错。

相关推荐

Global site tag (gtag.js) - Google Analytics