The previous Web project is already based on the Spring MVC framework and now needs to do a Dynamic Web page refresh feature, using DWR push Technology, server-side updates, immediately displayed on the Web page.
1. Import Dwr.jar Package
2. Configure the Web. xml file, and all the mappings are intercepted by the spring MVC controller and then forwarded by the controllers.
<servlet>
<servlet-name>testDispatcher</servlet-name>
<servlet-class> org.springframework.web.servlet.dispatcherservlet</servlet-class>
<init-param>
< Param-name>contextconfiglocation</param-name>
<param-value>/web-inf/config.xml</ param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name >testDispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</ servlet-mapping>
<servlet-mapping>
<servlet-name>testDispatcher</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
3. Configure the information about DWR in the container in the Web tier.
<!--scanning annotations--
<context:component-scan base-package= "Springmvc" ></context:component-scan>
<!--View Resolver--
<bean
class= " Org.springframework.web.servlet.view.InternalResourceViewResolver "
p:prefix="/view/"p:suffix=". jsp "/>
<!--through annotations, the URL is mapped to the controller, which registers defaultannotationhandlermapping and Annotationmethodhandleradapter by default-- >
<mvc:annotation-driven/>
<!--requires DWR to map util.js and engine.js to Dwrcontroller--
<dwr: url-mapping/>
<!--Configuring the DWR controller, if you want to use push, you must set the activereverseajaxenabled-->
<dwr:controller id= "Dwrcontroller" debug= "true" >
<dwr:config-param name= "activereverseajaxenabled"
value= "true"/ >
</dwr:controller>
<dwr:configuration></dwr:configuration>
4. After the above configuration, the Spring MVC controller will be able to connect to the Web page (DWR push), for example
ServerContext ServerContext = Servercontextfactory.get ();
collection<scriptsession> scriptsessions = ServerContext
. getallscriptsessions ();
Util Util = new Util (scriptsessions);
Scriptbuffer Scriptbuffer = new Scriptbuffer ();
Pass the object data to the Showconvertonetime () function
scriptbuffer.appendscript ("Showconvertonetime (") in JavaScript. AppendData (Object)
. Appendscript (");");
Util.addscript (Scriptbuffer);