Java+blazeds+Flex的例子 - 韦庆礼的专栏 java C# .NET J - CSDN博客

2009-11-06 21:02:20 作者:lekaihuai 来源: 浏览次数:0 网友评论 0

Java+blazeds+Flex的例子 收藏

由于Flex不提供操作数据库的工具,所以必须和其他语言通信来操作数据库。blazeds是连接Java和Flex的工具,它是完全免费、开源的,大家可以去网上搜索下载。

要使用到的工具:

Tomcat 6.0

MyEclipse 6.5

Flex Builder 3

blazeds

打开MyEclipse,新建一个Java Web工程,工程名Test,然后建包,写一个简单的方法如下:

package com.demo;

public class HelloWorld {

    public String sayHello(String name) {
        return"hello," + name;

    }

}

解压blazeds,复制WEB-INF文件夹,覆盖掉你的Test工程下的WebRoot下的WEB-INF文件夹。

打开Test工程下的WebRoot\WEB-INF\flex\remoting-config.xml这个文件,插入以下代码:

  1. <destination id="Hello">  
  2.        <properties>  
  3.            <source>com.demo.HelloWorld</source>  
  4.        </properties>  
  5.  </destination>

打开Flex Builder 3,新建一个web application工程,工程名FlexTest,服务器技术(server technology)选择none,然后next,在output folder(指定输出路径)里,选择刚才建立的Java工程Test的WebRoot目录。(一定要指定对)   然后Finish。

打开FlexText.mxml,代码如下:

view plaincopy to clipboardprint?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">  
  3. <mx:Script >        
  4. <!--[CDATA[ import mx.rpc.events.FaultEvent;      
  5.    import mx.rpc.events.ResultEvent;      
  6.       [Bindable]      
  7.       private var helloResult:String;     
  8.         
  9.       private function Hello():void {      
  10.      test.sayHello(inputText.text);    //通过RemoteObject的对象test,直接调用Java端的方法   
  11.         }      
  12.           
  13.        private function resultHandler(event:ResultEvent):void {      
  14.           helloResult = event.result as String;      
  15.        }   
  16.          
  17.    ]]-->     
  18. </mx:Script >  
  19. <mx:RemoteObject id="test" destination="Hello" result="resultHandler(event)" endpoint="/Test/messagebroker/amf"/>  
  20.    <mx:Label text="输入文字" id="nameLabel" x="19" y="77"/>  
  21.    <mx:Label id="resultLabel" text="{helloResult}" width="205" x="78" y="30" fontSize="13" fontWeight="bold" color="#FA7A08"/>  
  22.    <mx:TextInput id="inputText" x="78" y="73"/>  
  23.    <mx:Button label="HelloWord" id="Button" click="Hello()" x="101" y="126"/>  
  24.    <mx:HBox x="10" y="10" width="305" height="221" themeColor="#6E4AF7">  
  25.    </mx:HBox>  
  26. </mx:Application>  

注意:在RemoteObject标签下的destination属性的值,一定要和Java工程的remoting-config.xml中的destination的id一样。endpoint的值要和Java工程名一样,例如“/aaa//messagebroker/amf”,“/bbb//messagebroker/amf”

保存Flex工程,Flex会自动输出到Test工程下的WebRoot文件夹下。

在MyEclipose下刷新Test工程,会在WebRoot下看到生成的新文件,打开 web.xml更改启动首页,把<welcome-file-list>标签下的<welcome-file>的值改为 FlexText.html(Flex生成的),如下:

    <welcome-file-list>
        <welcome-file>FlexText.html</welcome-file>
        <welcome-file>FlexText.htm</welcome-file>
    </welcome-file-list>

保存项目,发布到Tomcat,启动Tomcat服务,在IE中输入http://localhost:8080/Test/

就能看到效果了!

文章来源:http://blog.csdn.net/pengpeng2395/archive/2009/05/09/4159658.aspx

关键词:例子

[错误报告] [收藏] [打印] [关闭] [返回顶部]

最新图片文章

最新文章