FlexSession简单应用

package com.test;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import flex.messaging.*;
public class GETSESSION {

public GETSESSION() {
// TODO Auto-generated constructor stub
}
public void setSession(String atr,Object val){
HttpServletRequest request = FlexContext.getHttpRequest();
HttpSession session = request.getSession();
session.setAttribute(atr,val);
}
public Object getSession(String atr){
HttpServletRequest request = FlexContext.getHttpRequest();
HttpSession session = request.getSession();
return session.getAttribute(atr);
}

}

PS1:我的remoting-config.xml:

<destination id="gethttpsession">
<properties>
<source>com.test.GETSESSION</source>
<scope>application</scope>
</properties>
</destination>

PS2:返回的OBJECT如果想要与AS3的OBJECT转化的话这个类要实现序列化(Serializable),还必须有get set方法,maybe flex access to the object with this javacode

mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:RemoteObject id = "ro" destination="gethttpsession" source="servlet">
<mx:method name="getSession" result="getresult(event)"/>
</mx:RemoteObject>
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
private function getresult(event:ResultEvent):void{
var cid:String = event.result as String;
Alert.show(cid);
}
private function getsession():void{
ro.getSession("user");
//ro.addEventListener(ResultEvent.RESULT,getcomid);
}
private function init():void{ro.setSession("user","http://bjutren.spaces.live.com/");
}
]]>
</mx:Script>
<mx:Button x="125" y="89" label="setsession" click="init()"/>
<mx:Button x="125" y="119" label="getsession" click="getsession()"/>

</mx:Application>

你可能感兴趣的:(xml,servlet,Flex,Access)