简单的j2ee+flex 两个独立工程的通信例子

环境:eclipse 3.5 + tomcat 6.0 + flex builder 3.0 + blazeds-turnkey-3.2.0.3978.zip(adobe网站上下载)

 

(因为不能放截图所以只能叙述了)

 

1,新建一个java web项目 例名为 :testjava;

 

2,在此工程中写一个简单的类:

 

 

        package cn.com;

 


       public class InfoTest {

 

 

          public String seeHello() {


             return "Hello World";
         }

 

       }

3,在testjava工程加与flex通信环境:

  

   解压blazeds-turnkey-3.2.0.3978.zip,找到里面的blazeds.war,将它解压,并将解压后的blazeds文件夹里的flex文件夹放入testjava>>WebContent>>WEB-INF 

   编辑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>
         <destination id="InfoTest ">//这个与flex 中的RemoteObject对应  

             <properties>
             <!-- 写上完整的与flex通信的类名(包名+类名) -->
             <source>cn.com.InfoTest </source>
             </properties>
         </destination>
         </service>

   

    再编辑web.xml:

 

         将blazeds.war解压后,找出/WEB-INF/web.xml 将这几行代码贴到testjava工程的web.xml中:

           <listener>
              <listener-class>flex.messaging.HttpFlexSession</listener-class>
           </listener>

           <!-- MessageBroker Servlet -->
           <servlet>
             <servlet-name>MessageBrokerServlet</servlet-name>
                <servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
             <init-param>
                <param-name>services.configuration.file</param-name>
                <param-value>/WEB-INF/flex/services-config.xml</param-value>
             </init-param>
             <load-on-startup>1</load-on-startup>
          </servlet>

          <servlet-mapping>
             <servlet-name>MessageBrokerServlet</servlet-name>
             <url-pattern>/messagebroker/*</url-pattern>
          </servlet-mapping>

 

 

 

 

4,将工程部署到tomcat上,并启动

 

5,在flex builder 中建一个flex project (名为testflex)

  

   注意界面选项:a. Application type 选择 Web application(runs in Flash Player)

                 b. Server technology:

                          Application server type 选择J2EE 点next

                 c. Server location:

                          Root folder:选上testjava工程的地址(如 D:/project/testjava/WebContent)

                          Root URL:写上testjava工程的访问路径(如 “http://localhost:8080/testjava”)

                          Context root: testjava(web工程名)其余的不用动直到finish

6,编辑testflex中的testflex.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.FaultEvent;
        import mx.controls.Alert;
        import mx.rpc.events.ResultEvent;
      
        private function resultHandler(event:ResultEvent):void {
            Alert.show(event.result.toString(), "连接成功");
        }
      
        private function faultHandler(event:FaultEvent):void {
            Alert.show(event.fault.toString(), "连接失败");
        }
        ]]>
    </mx:Script>
  
    <!-- destination 属性值就是testjava中 remoting-config.xml 中 destination 的 id -->
    <mx:RemoteObject id="remoteObject"
                      destination="InfoTest "
                     result="resultHandler(event)"
                     fault="faultHandler(event)"/>
  
    <mx:Button label="连接testjava" click="remoteObject.seeHello()" x="256.5" y="197"/>
</mx:Application>

 

 

7,最后选中testflex.mxml运行(Run Application)  即可

 

若无效果出现.....get flash,则你可用firefox查看效果试试(将flex开发工具属性中的的Web Browser选为firefox,并把flex--Profiler--Player/Browser 中配置flashPlay用firefox的exe文件)                       

 

 

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值