flex blazeDS(java)

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

remoting-config.xml配合使用

mxml中重要代码片段

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

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

 

<?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>

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

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

protected function loginBtn_clickHandler(event:MouseEvent):void
{
myFlex.getUser(userName.text,passWord.text);		
}

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

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

protected function myFlex_resultHandler(event:ResultEvent):void
{
	str=event.result as String;
	//Alert.show(str);
	if(str=='success'){
	currentState='mainState';
	}else{
	shake.play();   
	}
}

 

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

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

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";
		}
    }

		
}

 

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

转载链接:http://javacrazyer.iteye.com/blog/702791

<mx:RemoteObject id="recipeService" destination="fluorine"
source="oreilly.cookbook.FlexService" showBusyCursor="true"
result="roResult(event)" fault="roFault(event)" />
<mx:Script>
<![CDATA[
private function initApp():void {
// we have to register the object for the result to be able
// to properly cast as the RecipeVO
flash.net.registerClassAlias("oreilly.cookbook.vo.RecipeVO",
RecipeVO);
}
public function serviceResult(e:ResultEvent):void {
var rec:RecipeVO = (e.result as RecipeVO)
}
public function serviceFault(e:FaultEvent):void {
trace(" Error :: "+(e.message as String));
}
]]>
</mx:Script>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值