flex blazeds java_Flex+BlazeDS+java通信详细笔记

整了很长时间的通信,还是一直有一点问题。现在搞定了,记录一下,也跟有需求的同学们共享。

我重新把所有的过程再做一遍。

1新建Flex+BlazeDS+JAVA项目

右键、新建Flex项目

aecef0dbe9c703e1803b98fac04f9760.png

dad2cad107113ad8015d5cbad6d31db3.png

acec9659d97ca2be515bfdf5c5b55bac.png

其中blazeds.war提供下载,你可以去官网,或者从我这里:

http://yunpan.cn/QGzSwiyinUFiS  访问密码 25a8

2结构分析

23c07a54d9b5778a0a32fcf343ae10d1.png

flex_src是前台flex包

src是后台java包

WebRoot是输出文件包

重点就在WEB-INF

里边有blazeDS的lib,有flex的配置文件,包括messageing-config.xml,proxy-config.xml,remoting-config.xml,services-config.xml

5599e41091c07380b297b9f51cbd52a9.png

3 写后台

b39ed53f727c6ed7c1d3e2e7d612dd54.png

packagecom;public classHelloWorld {publicString getString(String name){

System.out.println("daole");return "这里是后台-:-这里是前台"+name;

}

}

4写配置文件--修改WebRoot》WEB-INF》flex>remoting-config.xml

增加

com.HelloWorld

7109e27dc03912b9c8c41d821cd09f56.png

affd8f59cfbb5cf04c74b763ba85d837.png

5写前台

a286a34add8769d1a9d9d9bd72e7d044.png

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

protectedfunction resultHandler(event:ResultEvent):void{//TODO Auto-generated method stub

Alert.show("进入result");

Alert.show(event.result.toString(),"提示");

}

protectedfunction faultHandler(event:FaultEvent):void{//TODO Auto-generated method stub

Alert.show("进入faultHandler");

Alert.show(event.fault.toString(),"提示");

}

]]>

View Code

其中,RemoteObject 的id是之后要引用的函数名,destination对应配置文件的引用名。

6按理说到这里前后台就配置完成了,但是还有一点点小问题,我们运行一下,在Tomcat右键Add Deployment。运行Tomcat

763ca5ab5fdd13f6fd087ed7d9f8ce8b.png

f72c81fcd40b1695ef7c05a33376f23c.png

发现程序进入了FAULT,没有进入RESULT,通道URL是url: 'http://localhost:8080/WebRoot/messagebroker/amf'

明显是路径错了,我们运行项目的路径是http://localhost:8080/PushTest6/PushTest6.html,结果被替换成了WebRoot。

Debug,找到如下图路径的配置文件

e4880d4f359faaf95c7c73c5c2134c38.png

问题来了,通道是默认的,都是变量,可以替换

{context.root}被替换成了WebRoot了呗。

先手动改了my-amf的通道路径看看能不能用。

这里要注意重新清理项目,否则配置文件仍然是默认的。

23b646ead55de505cf0a0833fe6d39f1.png

明显修改了路径是可以的。但这样修改似乎不太好。我们想办法修噶器ontext.root变量。找到项目文件夹的.flexProperties文件,笔记本打开。

ffca7aac67175d26f753e1c6d80972be.png

把serverContextRoot="/WebRoot" 改成serverContextRoot="/PushTest6"

成功了。改回来,看看还有没有别的办法。

办法2:

项目右键,属性,

ce430feb692313529c9a6ce3888abb74.png

附加的编译参数,增加

-context-root "\PushTest6"

-services "D:/Workspace/PushTest6/WebRoot/WEB-INF/flex/services-config.xml" -locale en_US-context-root "\PushTest6"

报错说配置变量compiler.contex-root仅能设置一次。看来要把.flexProperties的删掉才行

试试看,

修改为

解决了。

5fe1aee7d9d0efe550943ea307373a5d.png

7穿插解决一个小问题

由于“RemoteObject”声明未实现“mx.core.IUIComponent”,它必须包含在 标签中 怎么解决

把 RemoteObject 标签放到 标签中就可以了,如:

8增加一个能够输入参数的代码

前台

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

protectedfunction resultHandler(event:ResultEvent):void{//TODO Auto-generated method stub

Alert.show("进入result");

Alert.show(event.result.toString(),"提示");

}

protectedfunction faultHandler(event:FaultEvent):void{//TODO Auto-generated method stub

Alert.show("进入faultHandler");

Alert.show(event.fault.toString(),"提示");

}

protectedfunction remotingSayHello(event:Event):void{//TODO Auto-generated method stub

var iname:String =tiName.text;

say.getHelloWorld(iname);

Alert.show("1");

}

]]>

View Code

后台

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

packagecom;public classHelloWorld {publicString getString(String name){

System.out.println("daole");return "这里是后台-:-这里是前台"+name;

}publicString getHelloWorld(String name){

System.out.print("执行到了getHelloWorld这里");return "HelloWorld!"+name;

}

}

View Code

源代码分享一下吧:

http://yunpan.cn/QGzvBUYieXvVS  访问密码 20d7

请尊重作者劳动成果。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值