Use DWR in SPRINGMVC to focus on its configuration.
1. Configuration of the Web. xml file
Increase the DWR interception in the Dispatcherservlet to replace the Dwrservlet.
Change the configuration as follows:
1 <servlet>2 <Servlet-name>Mvc</Servlet-name>3 <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class>4 <Load-on-startup>1</Load-on-startup>5 </servlet>6 7 <!--Configuring DWR interception -8 <servlet-mapping>9 <Servlet-name>Mvc</Servlet-name>Ten <Url-pattern>/dwr/*</Url-pattern> One </servlet-mapping> A <servlet-mapping> - <Servlet-name>Mvc</Servlet-name> - <Url-pattern>/</Url-pattern> the </servlet-mapping>
Of course, if you don't want to use the spring servlet you can also use the Dwrspringservlet provided by DWR. The configuration is as follows:
1 <servlet>2 <Servlet-name>Dwr</Servlet-name>3 <Servlet-class>Org.directwebremoting.spring.DwrSpringServlet</Servlet-class>4 <Init-param>5 <Param-name>Debug</Param-name>6 <Param-value>True</Param-value>7 </Init-param>8 </servlet>9 <servlet-mapping>Ten <Servlet-name>Dwr</Servlet-name> One <Url-pattern>/dwr/*</Url-pattern> A </servlet-mapping>
2. Configuring the Springmvc File
Before you configure the Springmvc file, you need to add the Dwr namespace to the spring configuration file. According to official documents: if you use namespaces or annotations, you need to spring2. x above version, DWR2. X or later.
The namespaces that need to be joined are as follows (red section):
1 <Beans2 xmlns= "Http://www.springframework.org/schema/beans"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4 xmlns:dwr= "Http://www.directwebremoting.org/schema/spring-dwr"5 xsi:schemalocation= "Http://www.springframework.org/schema/beans6 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd7 HTTP://WWW.DIRECTWEBREMOTING.ORG/SCHEMA/SPRING-DWR8 http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">
The DWR configuration is as follows:
1 <!--DWR Configuration -2 <Dwr:annotation-config/>3 <Dwr:controllerID= "Dwrcontroller"Debug= "true">4 <Dwr:config-paramname= "activereverseajaxenabled"value= "true"/>5 </Dwr:controller>6 <dwr:url-mapping/>7 <Dwr:annotation-scanBase-package= "com.bigbang.*"Scandatatransferobject= "true"Scanremoteproxy= "true" />8
Dwr:annatation-config is an open DWR annotation scan that scans classes under the path based on the base-package configuration of Dwr:annatation-scan, and the next two configurations are the two commonly used annotation types.
Dwr:controller is limited to SPRINGMVC inside, it can add some configuration parameters, such as activereverseajaxenabled turn on reverse Ajax for push. If you do not configure the controller, you need to configure dwr:url-mapping, otherwise you will not be able to find the engine.js and interface.js files that are required by DWR in the page.
If you don't use annotations, you can also do this using the configuration method, as shown in the following example:
1 <BeanID= "Timeconvert"class= "Com.mycompany.ui.util.TimeConvert">2 <Dwr:remoteJavaScript= "Ajaxtimeconvert">3 <Dwr:includeMethod= "Convert" />4 </Dwr:remote>5 </Bean>
The above configuration dwr:remote equivalent to annotation @remoteproxy,dwr:include equivalent to annotation @remotemethod, if you want to increase the converted object data, you can use Dwr:convert, Equivalent to annotation @datatransferobject.
Using DWR in SPRINGMVC