flex j2ee开发

 

首先下载最新的 BlazeDS

 

http://opensource.adobe.com/blazeds/

 

最新BlazeDS下载地址.

 

http://opensource.adobe.com/wiki/display/blazeds/Release+Builds

 

下面就开始使用flex 创建一个 带java 的web 工程了.

 

创建工程

 

下载的是一个 war 文件..不用解压缩. 这个在创建工程的时候用到.

 


创建一个 flex的工程.
 

 选择 J2EE.

设置 flex 生成文件目录.我是直接修改成WebContent/flex_web文件夹下面

方便flex 编译后 直接放到这个地方.而不用再拷贝一下了.
 

设置flex 源文件 目录.
 


 

 

这样编译后的flex 就放到 WebContent下面的flex_web文件夹了.

而编译后的java 还放到 WEB-INF/classes文件夹下面.

并且在war里面的lib也一起拷贝过来了.


 然后启动tomcat.6.0

 

就可以访问.

运行远程调用.

然后引用 flex 开发宝典的例子.


下载地址.:

 

http://as.wiley.com/WileyCDA/WileyTitle/productCd-0470287640,descCd-DOWNLOAD.html?filter=DOWNLOAD

 

第 chapter24 的源文件夹.

 

修改配置编译文件.选择工程属性.

 

添加源文件.

 


然后 修改

 

remoting-config.xml

 

添加

Xml代码 复制代码
  1. <destination id="helloClass">  
  2.         <properties>  
  3.             <source>flex3Bible.ROService</source>  
  4.             <scope>application</scope>  
  5.         </properties>  
  6.     </destination>  

 

添加一个远程访问的类.

 

类就是一个普通的pojo类.

 

Java代码 复制代码
  1. public class ROService {   
  2.   
  3.     public ROService() {   
  4.         System.out.println("初始化类.");   
  5.     }   
  6.   
  7.     public String helloWorld() {   
  8.         System.out.println("函数被调用.");   
  9.         return "Hello from the world of Java";   
  10.     }   
  11. ...  

public class ROService {

	public ROService() {
		System.out.println("初始化类.");
	}

	public String helloWorld() {
		System.out.println("函数被调用.");
		return "Hello from the world of Java";
	}
...

flex调用代码:

Java代码 复制代码
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  
  3.   backgroundColor="#EEEEEE">   
  4.      
  5.   <mx:Script>   
  6.     <![CDATA[   
  7.       import mx.rpc.remoting.mxml.Operation;   
  8.       private function callIt():void  
  9.       {   
  10.         var op:Operation = roHello.getOperation("helloWorld") as Operation;   
  11.         op.send();   
  12.       }   
  13.     ]]>   
  14.   </mx:Script>   
  15.      
  16.   <mx:RemoteObject id="roHello" destination="helloClass"/>   
  17.        
  18.   <mx:Label text="Hello from BlazeDS!" fontSize="14" fontWeight="bold"/>   
  19.      
  20.   <mx:Button label="Click to say hello" click="callIt()"/>   
  21.      
  22.   <mx:Label text="{roHello.helloWorld.lastResult}"  
  23.     fontSize="14" fontWeight="bold"/>   
  24.      
  25. </mx:Application>  

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  backgroundColor="#EEEEEE">
  
  <mx:Script>
    <![CDATA[
      import mx.rpc.remoting.mxml.Operation;
      private function callIt():void
      {
        var op:Operation = roHello.getOperation("helloWorld") as Operation;
        op.send();
      }
    ]]>
  </mx:Script>
  
  <mx:RemoteObject id="roHello" destination="helloClass"/>
    
  <mx:Label text="Hello from BlazeDS!" fontSize="14" fontWeight="bold"/>
  
  <mx:Button label="Click to say hello" click="callIt()"/>
  
  <mx:Label text="{roHello.helloWorld.lastResult}"
    fontSize="14" fontWeight="bold"/>
  
</mx:Application>

 

 

 然后访问 tomcat 地址:

 

http://127.0.0.1:8080/chapter24_test/flex_web/CallOperation.html

 

发现调用不成功.弹出 debug 错误信息. (ie 下面安装了 flashplayer_10_ax_debug)

 


从错误信息可以很明显的发现是 访问不到服务.

 

'http://127.0.0.1:8080/WebContent/messagebroker/amf'"

 

我的tomcat 路径不是这个 .WebContent是文件夹的名字.

 

最后找到问题.

 

修改 工程属性 的 serve 配置.

 


修改了配置文件后. 重新编译 flex 文件.

不知道这个配置文件是否和flex生成的文件有关系.就重新编译了下.

 

访问页面可以调用.

 


显示 是从 java的服务端调用.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值