在csdn上看到这么一个例子
<init-param>
<param-name>crossDomainSessionSecurity </param-name>
<param-value>true </param-value>
</init-param>
<init-param>
<param-name>pollAndCometEnabled </param-name>
<param-value>true </param-value>
</init-param>
接收页面初始化
window.onload = init;
function init() {
dwr.engine.setActiveReverseAjax(true);
} 页面接收函数
//服务器推的消息
function receiveMessages(result) {
........
} 服务器端推函数 /**
* dwr为服务器端推而做的,应用到还原时候,异步回显执行结果
*/
public void realTimeOperate(String result) {
WebContext wctx = WebContextFactory.get();
ScriptBuffer sb = new ScriptBuffer();
sb.appendScript("receiveMessages(").appendData(result).appendScript(
");");
ServerContext sctx = ServerContextFactory.get(wctx.getServletContext());
Collection <ScriptSession> pages = sctx
.getScriptSessionsByPage("/receive.jsp");
for (ScriptSession session : pages) {
session.addScript(sb);
}
}
开始那段能明白,就是后面这段我有点不是很懂
public void realTimeOperate(String result) {
WebContext wctx = WebContextFactory.get();
ScriptBuffer sb = new ScriptBuffer();
sb.appendScript("receiveMessages(").appendData(result).appendScript(
");");
ServerContext sctx = ServerContextFactory.get(wctx.getServletContext());
Collection <ScriptSession> pages = sctx
.getScriptSessionsByPage("/receive.jsp");
for (ScriptSession session : pages) {
session.addScript(sb);
}
}
有几个问题,这个方法怎么样去触发?是不是反推送不用去触发?
比如说我要每一段时间查一下数据库,有新数据就像客户端推送,应该怎样谢,上面的代码片段中我没研究明白
最后一个问题就是怎样设置时间!~
请大家指教一下,谢谢大家!!!本来发在ajax那边...不过那边貌似人气不怎样.dwr也算是针对java的框架发在这边也应该说的过去...
<init-param>
<param-name>crossDomainSessionSecurity </param-name>
<param-value>true </param-value>
</init-param>
<init-param>
<param-name>pollAndCometEnabled </param-name>
<param-value>true </param-value>
</init-param>
接收页面初始化
window.onload = init;
function init() {
dwr.engine.setActiveReverseAjax(true);
} 页面接收函数
//服务器推的消息
function receiveMessages(result) {
........
} 服务器端推函数 /**
* dwr为服务器端推而做的,应用到还原时候,异步回显执行结果
*/
public void realTimeOperate(String result) {
WebContext wctx = WebContextFactory.get();
ScriptBuffer sb = new ScriptBuffer();
sb.appendScript("receiveMessages(").appendData(result).appendScript(
");");
ServerContext sctx = ServerContextFactory.get(wctx.getServletContext());
Collection <ScriptSession> pages = sctx
.getScriptSessionsByPage("/receive.jsp");
for (ScriptSession session : pages) {
session.addScript(sb);
}
}
开始那段能明白,就是后面这段我有点不是很懂
public void realTimeOperate(String result) {
WebContext wctx = WebContextFactory.get();
ScriptBuffer sb = new ScriptBuffer();
sb.appendScript("receiveMessages(").appendData(result).appendScript(
");");
ServerContext sctx = ServerContextFactory.get(wctx.getServletContext());
Collection <ScriptSession> pages = sctx
.getScriptSessionsByPage("/receive.jsp");
for (ScriptSession session : pages) {
session.addScript(sb);
}
}
有几个问题,这个方法怎么样去触发?是不是反推送不用去触发?
比如说我要每一段时间查一下数据库,有新数据就像客户端推送,应该怎样谢,上面的代码片段中我没研究明白
最后一个问题就是怎样设置时间!~
请大家指教一下,谢谢大家!!!本来发在ajax那边...不过那边貌似人气不怎样.dwr也算是针对java的框架发在这边也应该说的过去...
解决方案 »
- java.lang.ClassCastException: java.lang.String cannot be cast to common.User
- 各位高手帮小弟看下哪里错,用hibernary+spring自动生成数据库的表,启动服务没报错,但是数据库没生成任何表
- 关于Java高级编程(第2版) 死锁的讨论
- 一个javamail的奇怪问题
- 求一个判断数据库数据重复的算法
- formbean中接收下拉列表值的问题
- struts判断标签
- SPRING-FRMAEWORK是什么东西呀,能解释一下吗?或者给一些技术资源连接
- 在struts中怎么配置数据源
- 看看我的HTTP问题,怎么解决缓存问题,绝对给高分!
- Hibernate无限级分类的排序问题
- 怎么提取文件并写入到response流里面
但是现在又有几个新问题了public void realTimeOperate(String result)
{
WebContext wctx = WebContextFactory.get();
ScriptBuffer sb = new ScriptBuffer();
sb.appendScript("receiveMessages(").appendData(result).appendScript( ");");
ServerContext sctx = ServerContextFactory.get(wctx.getServletContext());
Collection <ScriptSession> pages = sctx.getScriptSessionsByPage("/receive.jsp");
for (ScriptSession session : pages)
{
session.addScript(sb);
}
}上述方法,我如果用dwr去触发,一点问题都没有。但是我想在action去触发这个方法,例如我象数据库插入一条数据,调用此方法,页面刷新出新数据。
我试了一下,调用的时候获取servercontext的时候,会报空指针,我换成了用request获取
但是sctx.getScriptSessionsByPage("/receive.jsp"); 这句又空指针了。。我百思不得其解
请高手指教一下,谢谢!