Flex+J 2 EEがFlexSessionを取得する方法

1651 ワード

-------web.xmlファイル
<listener>
        <listener-class>flex.messaging.HttpFlexSession</listener-class>
    </listener>

-----Javaコード
public class GetSeesion {
/**
  *  session
  * */
public void setSession(String name,String value){
  FlexContext.getFlexSession().setAttribute(name, value);
}
// session
public String getSession(String name){
  String userid=(String) FlexContext.getFlexSession().getAttribute(name);
  return userid;
}
}

------remoting-config.xmlに追加
<!--  session  -->
<destination id="sessionBiz">
        <properties>
            <source>com.ssfx.util.GetSeesion</source>
            <scope>application</scope>
        </properties>
    </destination>

------セッションの使用
<mx:RemoteObject id="sBiz" destination="sessionBiz" showBusyCursor="true">
  <mx:method name="setSession"/>
<mx:method name="getSession" result="sessionHandle(event)"/>
</mx:RemoteObject>
<script>
<![CDATA[
  sBiz.setSession("userId",txtUserId.text);
  sBiz.getSession("userId");
  /*  session  */ 
   private function sessionHandle(event:ResultEvent):void{
    var userCode=String(event.result);
    this.addPlanMess(userCode);
   }
]]>
</script>