首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

flex remoteObject 单例有关问题

2012-02-21 
flex remoteObject 单例问题flex 中使用 remoteObject方式 与 后台java通信实例:在mxml中 我定义了一个rem

flex remoteObject 单例问题
flex 中 使用 remoteObject方式 与 后台java通信
实例:在mxml中 我定义了一个remoteObject 对象,有个按钮, 当每次 点击按钮的时候
就通过remoteObject去调用 后台java的某个方法。
现在有个这样的问题:每次调用一次后台java方法 都会新建一个新的java对象实例
但是我想做到的是 每个浏览器session 对应一个java实例 该怎么做?
请高手支招!

[解决办法]
创建一个自定义容器,去实例化这个RepastModel。
里面实例化时,类似你写的单例。
但是从session里面取这个单例,如果当前session有,就取。没有就创建一个,并放到session里面。

要么这样做。
[解决办法]
看看这样可以不
flex--->remoteObject--->Service(里面创建RepastModel,创建时这样写)
RepastModel entity = null;
if (session.getAttribute("RepastModel") != null) {
entity = session.getAttribute("RepastModel") ;
} else {
entity = new RepastModel();
session.setAttribute("RepastModel", entity );
}

注意一点,现在的单例就是以session为单位的。并不是ClassLoader级别上的单例,这也正是你想要的效果

热点排行