dwr2 反向推送消息到前台,前台无响应

herofour444 2016-05-08 12:08:43
问题描述:
dwr的版本为2.0,框架比较老。
在一台电脑上开2个窗口A,B
现在消息能发送出去A发送给B,但是B不能实时收到。dwr在后台没有将消息推送到前台的方法中。

//后台
//用来存储session的map
private static Map<String,ScriptSession> ONLINE_SCRIPTSESSIONS=new HashMap<String,ScriptSession>();
//用户进入页面的时候将session取出加入map中
WebContext wctx = WebContextFactory.get();
ScriptSession scriptSession = wctx.getScriptSession();
String userID = getUserSession().getUserID();
ONLINE_SCRIPTSESSIONS.put(userID,scriptSession);
//发送消息后,进行推送到前台的myceshi
ScriptBuffer mainScript = new ScriptBuffer();
mainScript.appendScript("myceshi();");
//ONLINE_SCRIPTSESSIONS.get(toUserCode),打印发现,获取的session是正确的。
if(ONLINE_SCRIPTSESSIONS.containsKey(toUserCode))
{
ONLINE_SCRIPTSESSIONS.get(toUserCode).addScript(mainScript);
}



前台html:


<script type='text/javascript' src='/pen/dwr/engine.js'></script>
<script type='text/javascript' src='/pen/dwr/interface/MessageService.js'></script>
<script>
$(document).ready(function(){
//开启翻转
dwr.engine.setActiveReverseAjax(true);
});
//测试的,看是否推送成功
function myceshi()
{
alert("fasdfsdfasdfasdf");
}


web.xml中配置

<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>
org.directwebremoting.servlet.DwrServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<description>使用服务器推技术(反转AJAX)</description>
<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>
<init-param>
<param-name>config</param-name>
<param-value>/**/dwr.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
...全文
279 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wahahachuang6 2016-08-08
  • 打赏
  • 举报
回复
想要建立实时web,推荐GoEasy的web实时推送,他们是专注做Web实时推送的, 网上一搜就有其用户自己总结的实例和感想,使用非常简单,都在说几分钟就可以实现推送了.
筱芙淘趣坊 2016-05-10
  • 打赏
  • 举报
回复
http://chenjumin.iteye.com/blog/690071
herofour444 2016-05-08
  • 打赏
  • 举报
回复
正常来说应该可以调用前台的myceshi方法的。
herofour444 2016-05-08
  • 打赏
  • 举报
回复
dwr的定义:

<dwr>
	<allow>
		<create creator="spring" javascript="SAM_MessageService">
			<param name="beanName" value="SAM_MessageBO" />
		</create>
		
		<convert converter="bean" match="com.pul.sam.message.data.*" />
	</allow>
	
	<signatures>
  		<![CDATA[
  			import com.pul.sam.message.data.TMessage;
  			SAM_MessageService.changeState(List<TMessage> list);
  			SAM_MessageService.opDeleteMessages(List<TMessage> list);
		 ]]>
	</signatures>
</dwr>
beans的定义

<bean id="SAM_MessageBO" class="com.pul.sam.message.MessageBO" parent="baseBO">
	<property name="instantMessageService">
			<ref bean="instantMessageService" />
	</property>
herofour444 2016-05-08
  • 打赏
  • 举报
回复
困扰了1天了,求大神帮忙看看

81,122

社区成员

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

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