服务端使用jetty
dwr2.0.3
web.xml配置为:
在firefox中,推送能正常进行,实时刷新数据,但是在IE和opera中不能实时刷新,大约隔一分钟才刷新一次。查阅dwr文档解释如下:
The problem with full streaming is that it requires HTTP chunked mode which sometimes fails with network proxies, mod_jk, and other network scanners. If you try full streaming and find that messages are only getting through every 60 seconds, this could be why. DWR version 2.0.3 and before used this as the default. From version 2.0.4 the default is to use Early Closing Mode.
意思是在2.0.3版本中缺省使用的full streaming模式需要HTTP块模式,而在网络代理,mod_jk,其他网络扫描器等情况下,会导致推送失败,每隔60秒才刷一次。而从2.0.4版本开始缺省使用Early Closing mode,避免了这一问题。
在2.0.3中要使用Early Closing mode,需要在配置中加入如下代码:
在这一模式下,如果没有数据推送,长连接只保持60秒,但是如果有数据,长连接将在第一次数据推送后继续保持长连接500秒。
通过以上修改,IE和opera都能正确推送,实时刷新。问题解决
dwr2.0.3
web.xml配置为:
- <servlet>
- <servlet-name>dwr-invoker</servlet-name>
- <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
- <init-param>
- <param-name>activeReverseAjaxEnabled</param-name>
- <param-value>true</param-value>
- </init-param>
- <init-param>
- <param-name>initApplicationScopeCreatorsAtStartup</param-name>
- <param-value>true</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
The problem with full streaming is that it requires HTTP chunked mode which sometimes fails with network proxies, mod_jk, and other network scanners. If you try full streaming and find that messages are only getting through every 60 seconds, this could be why. DWR version 2.0.3 and before used this as the default. From version 2.0.4 the default is to use Early Closing Mode.
意思是在2.0.3版本中缺省使用的full streaming模式需要HTTP块模式,而在网络代理,mod_jk,其他网络扫描器等情况下,会导致推送失败,每隔60秒才刷一次。而从2.0.4版本开始缺省使用Early Closing mode,避免了这一问题。
在2.0.3中要使用Early Closing mode,需要在配置中加入如下代码:
- <init-param>
- <param-name>maxWaitAfterWrite</param-name>
- <param-value>500</param-value>
- </init-param>
通过以上修改,IE和opera都能正确推送,实时刷新。问题解决