Flex BlazeDS Java 使用
配置对 Java 服务的访问通过此项目配置可创建将基于 Java 的服务类与远程对象访问服务选项结合使用的 Flex 项目。如果未选择任何选项但使用了 Java 服务器,则会在该服务器根文件夹下创建一个输出文件夹。如果安装了 Eclipse Web Tools Project (WTP) 插件,则可以创建具有或不具有远程对象访问服务的 Java 和 Flex 组合项目。
注: LiveCycle Data Services 和 BlazeDS 仅支持 Flex SDK 的特定版本。检查
LiveCycle Data Services Compatibility Matrix 查看您的 LiveCycle Data Service 版本支持哪些版本的 Flex SDK。兼容性列表还列出 BlazeDS 支持的 Flex SDK 版本。
具体实现步骤 1.环境搭建 ? ?a.Win7 ? ?b.tomcat6.0 安装路径即【tomcat-home】 ? ?c.tomcat 运行端口8080 ? ?d.flex builder 4.6 2.假定接下来的这些介绍你都知道 ? ?a.创建java class ? ?b.使用Flex builder 4.6 ? ?c.暂停和启动tomcat 3.下载BlazeDS ? ?a.http://opensource.adobe.com/wiki/display/blazeds/Release+Builds ? ?b.下载最新BlazeDS binary ? ? ? ?i.以.zip格式保存到电脑上 ? ? ? ?ii.在.zip中有两个文件blazeds.war及blazeds-bin-readme.html ? ? ? ?iii.将blazeds.war放到【tomcat-home】webapps目录下 ? ?c.如果tomcat已启动,请重启 ? ?d.浏览webapps目录 ? ? ? ?i.你应该能找到一个名为blazeds的文件夹 ? ? ? ?ii.在blazeds下有一个web-inf的文件夹 ? ? ? ?iii.在web-inf下有几个文件夹其中一个叫classes,用来存放java class,以便flex 应用使用 ? ? ? ?iv.我们在remote-config.xml放置一个节点以便flex 应用和java class连接起来 4.使用java ide创建class ? ? package example; publicclassHelloWorld { public HelloWorld() { } public String getHelloWorld() { return"Hello From Java!"; } 编译java源文件将生成的class文件放置到classes文件下 5.将接下来的node添加到【tomcat-home】webappsblazedsWEB-INFflexremoting-config.xml中</default-channels>之后,</service>节点之前
<destination id="helloworld"> <properties> <source>example.HelloWorld</source> </properties> <adapter ref="java-object"/> </destination> 6.重启tomcat 7.创建flex 应用命名为HelloWorld 在服务器设置中选者BlazeDS 验证配置 根文件夹D:apache_tomcatwebappsblazeds 根URL(U)http://localhost:8080/blazeds/ 上下文根目录(C):/blazeds 点击finish 8.在HelloWorld.mxml中添加以下代码在 <mx:Application> </mx:Application> tags之间
<fx:Script> <![CDATA[
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.utils.ObjectUtil;
import mx.controls.Alert;
import mx.utils.StringUtil;
private function resultHandler(event:ResultEvent):void
{
//used for debugging - shows details about result
//returned by the Java class method
Alert.show( ObjectUtil.toString(event.result) );
}
private function faultHandler(event:FaultEvent):void
{
Alert.show( ObjectUtil.toString(event.fault) );
}
]]> </fx:Script> <fx:Declarations>
<mx:RemoteObject id="ro" destination="helloworld"
source="example.HelloWorld"
result="resultHandler(event)"
fault="faultHandler(event)"/> </fx:Declarations> <mx:Panel x="10" y="10" width="440" height="200" layout="vertical" title="Test Flex 3 Using Java" borderColor="#008040" fontFamily="Arial" fontWeight="bold" fontSize="13">
<mx:Text text="Click The Button To Test Getting Data Into Flex From A Java Class" fontWeight="bold" width="250"/>
<mx:Spacer height="20"/>
<mx:Button label="Get Hello World!" click="ro.getHelloWorld()"/>
</mx:Panel> 9.运行Flex HelloWorld 应用点button将会出现Hello from java! 10.记住mx:RemoteObject中的destination和remote-config.xml文件中的destination 值一致 Trouble-shooting TipsIf you change the HelloWorld Java file then you'll need to copy the new class file into the[tomcat-home]webappsblazedsWEB-INFclasses folder in the correct package. Then you'll have to stop and restart Tomcat. If you change the remote-config.xml file,you'll need to stop and restart Tomcat. You may also need to rebuild your Flex application before running it again. Summary:How easily Flex works with ColdFusion Components (CFCs) is just another reason I miss ColdFusion. But my new company uses Java to develop their web applications and they are not going to change to ColdFusion. But I hope that eventually we will be able to use Flex on the front end and Java on the back end where it makes sense. But first I've got to get smart on how to integrate Flex and Java. So I've got alot of learning and trial and error. I'll keep you posted in this series of blog entries. Up next - sending information from Flex to a Java class. 总算写完了 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |