一、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);
}