Flex3与BlazeDS HelloWorld 详解
BlazeDS的下载和介绍:
http://opensource.adobe.com/wiki/display/blazeds/Release+Builds
有Tomcat的下载
http://flexorg.wip3.adobe.com/blazeds/3.0.x/milestone/3978/blazeds-bin-3.2.0.3978.zip
没Tomcat的下载
http://flexorg.wip3.adobe.com/blazeds/3.0.x/milestone/3978/blazeds-turnkey-3.2.0.3978.zip
下载后将blazeds.war部署到tomcat下即可。
Flex Builder插件的安装不再作介绍
开发工作为MyEclipse:
1.新建一个Flex工程
按照图中进行配置
2.下一步:
指定已经下载的blazeds.war
3.下一步.
配置url
4.完成后右键配置工程属性:
注意context的修改,不然运行程序会报404.
5.新建一个测试类:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
package com;
public class HelloWorld
{ public String say(String username)
{ System.out.println( "hello" );
return "你好!" + username;
} public String login(String username,String password)
{ System.out.println( "login" );
if (username.equals( "admin" ) && password.equals( "admin" ))
{ return "success" ;
} else
{ return "failure" ;
} } } |
6.配置web-inf/flex 下的remoting-config.xml文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<?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>
<!-- 目标java类 --> <destination id= "helloworld" >
<properties> <source>com.HelloWorld</source> </properties> </destination> </service> |
7.编写mxml文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
<?xml version= "1.0" encoding= "utf-8" ?>
<mx:Script> <![CDATA[ import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
//hello事件
private function helloClick(): void
{ this .hello.say( this .username.text);
} //登录事件
private function loginClick(): void
{ this .login.login( this .username.text, this .password.text);
} //处理hello事件 返回值
private function resultHandler(e:ResultEvent): void
{ Alert.show(e.result.toString()); } //处理登录事件返回值
private function resultLoginHandler(e:ResultEvent): void
{ Alert.show(e.result as String); } ]]> </mx:Script> <!--远程对象调用--> <mx:RemoteObject id= "hello" destination= "helloworld" result= "resultHandler(event)" />
<mx:RemoteObject id= "login" destination= "helloworld" result= "resultLoginHandler(event)" />
<mx:TextInput id= "username" x= "187" y= "99" width= "119" />
<mx:Label x= "123" y= "101" text= "username:" />
<mx:Label x= "123" y= "141" text= "password:" />
<mx:TextInput id= "password" x= "187" y= "139" width= "119" />
<mx:Button x= "241" y= "184" label= "Login" click= "loginClick()" />
<mx:Button x= "123" y= "184" label= "HelloWorld" click= "helloClick()" />
</mx:Application> |
7.找到bin-debug下的secondBlaze.html右键选择在Run on Server即可。
效果图