`
Merrygrass
  • 浏览: 165210 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

DWR服务器推(长连接)技术实现

阅读更多

一、DWR服务器推技术实现基本步骤:

1、利用WebContextFactory获取WebContext(页面上下文)

2、 设置要推送数据的页面

3、创建脚本流

4、获取ScriptSession

5、为每个页面 (ScriptSession)添加要更新的处理函数或者数据

二、具体实现代码如下:

  WebContext wcxt = WebContextFactory.get(); //获取页面上下文
  String currentpage = "/Chat1.1/leader_replay.jsp"; //当前页面
  ScriptBuffer buffer = new ScriptBuffer(); //脚本流
  buffer.appendScript("review();"); //添加前台脚本函数
  Collection<ScriptSession> pages = wcxt.getScriptSessionsByPage(currentpage);
  for(Iterator it = pages.iterator();it.hasNext();){
   ScriptSession othersession = (ScriptSession) it.next();
   othersession.addScript(buffer);
  }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics