flex连接java服务端

flex连接java服务端,使用BlazeDs框架
最近学习flex,关于flex连接java服务端做了个例子,最终效果如下图:
flex连接java服务端
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
	
	<fx:Script>
		<![CDATA[
			import mx.collections.ArrayList;
			import mx.controls.Alert;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			
			[Bindable]
			private var studentList:ArrayList;
			protected function login_clickHandler(event:MouseEvent):void
			{
				var loginName:String=names.text;
				var passwords:String=password.text;
				logins.login(loginName,passwords);//服务端的方法
				
			}
			protected function login_resultHandler(event:ResultEvent):void
			{
				if(event.result as String=="success"){
					//Alert.show("登录成功");
					mess.text="登录成功";
					studentList=getStu.getStudentList() as ArrayList;
				}else{
					Alert.show("用户名或密码错误");
				}
				
			}
			
			protected function getStudents_Handler(event:ResultEvent):void
			{
				studentList=event.result as ArrayList;
				
			}
			protected function login_faultHandler(event:FaultEvent):void
			{
				Alert.show("登录失败");
				
			}
			
		]]>
	</fx:Script>
	
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
		<s:RemoteObject id="logins" destination="Login" result="login_resultHandler(event)" fault="login_faultHandler(event)"/>
		<s:RemoteObject id="getStu" destination="getStudents" result="getStudents_Handler(event)" fault="login_faultHandler(event)"/>
	</fx:Declarations>
	<s:Panel title="登录" width="400" height="390">
		<s:VGroup>
			<s:Form id="loginForm">
				<s:FormItem label="用户名:">
					<s:TextInput id="names" width="150"/>
				</s:FormItem>
				<s:FormItem label="密  码:">
					<s:TextInput id="password" width="150"/>
				</s:FormItem>
			</s:Form>
			<s:HGroup paddingLeft="20" paddingRight="20">
				<mx:LinkButton id="register" label="注册"/>
				<s:Spacer width="50"/>
				<s:Button id="loginLabel" label="登录" click="login_clickHandler(event)"/>
			</s:HGroup>
			<s:Label id="mess" text="返回信息" color="red"/>
			<s:Panel title="学生列表">
				<s:DataGrid id="stu" dataProvider="{studentList}" width="240">
					<s:columns>
						<s:ArrayList>
							<s:GridColumn dataField="stuName" headerText="名称"/>
							<s:GridColumn dataField="gender" headerText="性别"/>
							<s:GridColumn dataField="age" headerText="年龄"/>
							<s:GridColumn dataField="classes" headerText="班级"/>
						</s:ArrayList>
					</s:columns>
				</s:DataGrid>
			</s:Panel>
		</s:VGroup>
	</s:Panel>
</s:Application>
 
 功能包含简单登录验证,登录成功后从服务端返回一个学生列表。用到的配置文件以及项目源代码在附件中。

你可能感兴趣的:(Flex,Flex,RemoteObject,blazeds,blazeds,jar包,jar包,Java配置文件)