初学DWR(版本为DWR3)自已写了个polling的demo不成功,有些问题弄不明白
注:版本前提为DWR3,使用polling
dwr.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN" "http://getahead.org/dwr/dwr3.0.dtd">
<dwr>
<allow>
<create creator="new" scope="application">
<param name="class" value="com.example.dwr.reverseajax.Test"/>
</create>
</allow>
</dwr>
web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="dwr">
<listener>
<listener-class>org.directwebremoting.servlet.DwrListener</listener-class>
</listener>
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<!-- polling模式 -->
<init-param>
<param-name>activeReverseAjaxEnabled</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>org.directwebremoting.extend.ServerLoadMonitor</param-name>
<param-value>org.directwebremoting.impl.PollingServerLoadMonitor</param-value>
</init-param>
<init-param>
<param-name>disconnectedTime</param-name>
<param-value>5000</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
</web-app>
Test.java
package com.example.dwr.reverseajax;
import org.directwebremoting.Browser;
import org.directwebremoting.ui.dwr.Util;
public class Test
{
public void start()
{
Browser.withCurrentPage(new Runnable()
{
public void run()
{
Util.setValue("chatlog", "<h1>"+System.currentTimeMillis()+"</h1>");
}
});
}
}
index.jsp
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type='text/javascript' src='dwr/engine.js'> </script>
<script type='text/javascript' src='dwr/interface/Test.js'> </script>
<script type='text/javascript' src='dwr/util.js'> </script>
<script type="text/javascript">
dwr.engine.setNotifyServerOnPageUnload(true);
Test.start();
</script>
</head>
<body onload="dwr.engine.setActiveReverseAjax(true);">
<hr/>
<ul id="chatlog"></ul>
</body