DWR3.0推送

回头不看 2011-05-05 10:44:38
最近在学DWR3.0推送的时候
String page = WebContextFactory.get().getContextPath() + "/index.jsp";
Browser.withPage(page, new Runnable() {
public void run() {
Util.setValue("clockDisplay", "发布消息啦!");
}
});

就是说我在chat.jsp发布一个消息时 如何才能将我要发布的消息推送到index.jsp页面上!
好像每次测试时
运行上面的方法时不运行到run方法
但是运行
// 推给所有用户
Browser.withAllSessions(new Runnable() {
public void run() {
Util.removeAllOptions("users");
Util.addOptions("users", users, "name");
Util.removeAllOptions("receiver");
Util.addOptions("receiver", users, "name");
}
});


// 推给指定用户
Browser.withCurrentPageFiltered(new ScriptSessionFilter() {
public boolean match(ScriptSession session) {
if (session.getAttribute("user") == null)
return false;
else
return ((User) session.getAttribute("user")).getName()
.equals(receiverid);
}
}, new Runnable() {
public void run() {
Collection<ScriptSession> colls = Browser.getTargetSessions();
for (ScriptSession scriptSession : colls) {
scriptSession.addScript(initFunctionCall(
"dwr.util.setValue", "sender", sender));
scriptSession.addScript(initFunctionCall(
"dwr.util.setValue", "msg", msg));
}
ScriptBuffer script = new ScriptBuffer();
script.appendScript("showMessage(").appendData(msg)
.appendScript(");");
}
});

这两个方法的时候没有问题 请问大家 是不是推送到指定页面要加什么特殊的配置吗?
...全文
2207 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
jason_yzxzy 2012-10-15
  • 打赏
  • 举报
回复
谁有详细的文档,会可运行的简单的工程,发一个3q 359051580@qq.com
star_zk 2012-09-10
  • 打赏
  • 举报
回复
请问 楼主 你这个问题解决了吗????
affect1210 2012-04-08
  • 打赏
  • 举报
回复
自己帮顶 大伙给个提示吧!
回头不看 2011-05-13
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 catoop 的回复:]
DefaultWebContext wctx = (DefaultWebContext) WebContextFactory.get(); // 这里是获取WebContext上下文
String currentPage = wctx.getCurrentPage();
Collection<ScriptSession> sessions = wctx.getScriptSessionsByP……
[/Quote]

能详细点么?或者能直接给个推送到指定页面的地址吗?谢谢!


[Quote=引用 8 楼 shuai45 的回复:]
首先,回答是可以的。
但是前提是要知道index的scriptSessionID。
DWR推送是通过scriptSessionID实现的,每个页面都会生成一个这样的ID,这样DWR可以通过它推往相关页面。这个页面是在引用相关DWR就生成的。
[/Quote]

那么就是说要推送到指定页面也必须建立一个连接对吗?
catoop 2011-05-12
  • 打赏
  • 举报
回复
DefaultWebContext wctx = (DefaultWebContext) WebContextFactory.get(); // 这里是获取WebContext上下文
String currentPage = wctx.getCurrentPage();
Collection<ScriptSession> sessions = wctx.getScriptSessionsByPage(currentPage);
这种使用的是当前页面推送,也就是你的chat.jsp
如果你要推送的index.jsp,上面2步就不需要了,直接把currentPage 修改为 /项目名称/index.jsp 即可,注意要以“/”开头。
deng8818 2011-05-12
  • 打赏
  • 举报
回复
楼上正解
DefaultWebContext 及 getScriptSessionsByPage才是要点
shuai45 2011-05-12
  • 打赏
  • 举报
回复
首先,回答是可以的。
但是前提是要知道index的scriptSessionID。
DWR推送是通过scriptSessionID实现的,每个页面都会生成一个这样的ID,这样DWR可以通过它推往相关页面。这个页面是在引用相关DWR就生成的。
javagxc 2011-05-07
  • 打赏
  • 举报
回复
帮你顶下,期待高手
回头不看 2011-05-06
  • 打赏
  • 举报
回复
没人知道么?
回头不看 2011-05-06
  • 打赏
  • 举报
回复
别沉了 自己继续顶
回头不看 2011-05-06
  • 打赏
  • 举报
回复
自己帮顶 大伙给个提示吧!

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧