blazeDS开发

还是以那个登录例子来说,登录请求在blazeDS来看不是直接发送URL串来请求,而是通过AS代码与web-info下的

remoting-config.xml配合使用

mxml中重要代码片段

<span style="font-size: medium;"><fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
&nbsp;<s:RemoteObject id="myFlex" destination="mytest" result="myFlex_resultHandler(event)"&nbsp; /></fx:Declarations>
</span>

 那么这个destination所指的名字就是remoting-config.xml中配置好的名称,具体内容是

<span style="font-size: medium;"><?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>

<!--这个代码片段指定处理登录的具体类全限定名-->
    <destination id="mytest" >
     <properties>
        <source>com.imgold.test.Login</source>
     </properties>
     </destination>

</service></span>

xml代码

 

<span style="font-size: medium;"><?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>

<!--这个代码片段指定处理登录的具体类全限定名-->
    <destination id="mytest" >
     <properties>
        <source>com.imgold.test.Login</source>
     </properties>
     </destination>

</service></span>

 

mxml中光有这个还不行,既然是登陆,肯定有点击发送及处理结果的方法

 

    下面来看下程序的点击登录按钮处理方法

 

<span style="font-size: medium;">protected function loginBtn_clickHandler(event:MouseEvent):void
{
myFlex.getUser(userName.text,passWord.text);		
}</span>

 这个getUser方法可是JAVA后台处理类程序中的具体方法

   上面remoteObject那个result方法是处理程序返回结果的

<span style="font-size: medium;">protected function myFlex_resultHandler(event:ResultEvent):void
{
	str=event.result as String;
	//Alert.show(str);
	if(str=='success'){
	currentState='mainState';
	}else{
	shake.play();   
	}
}</span>

 

其他MXML代码上次发的那个登录示例中有

    最后就看下程序处理类的具体代码

 

<span style="font-size: medium;">public class Login {

    public String getUser(String userName,String passWord){
    	ApplicationContext 
		context = new ClassPathXmlApplicationContext("applicationContext.xml");


		UserServiceImpl sf = (UserServiceImpl) context.getBean("userService");
		User user=sf.login(userName, passWord);
		System.out.println(user);
		if(user!=null){
			return "success";
		}else{
			return "fail";
		}
    }

		
}</span>

大功告成,blazeDS最基本的示例可以运行了

  

 

  

 

 

  

 

  

 

 

 

 

 

转载于:https://www.cnblogs.com/regalys168/p/3626882.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值