This article is based on building Jquery+springmvc+spring+hibernate+mysql platform
I. Preparatory work
1. Click here to download the relevant files and place the files in the corresponding folder of the IMS project.
Two. Introduction to the JAR package
1. Dwr-3.0.1.jar, support the minimum version of spring 4.3.4
Three. Introduction of related Documents
1. Web. xml
<?XML version= "1.0" encoding= "UTF-8"?><Web-appXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:web= "Http://xmlns.jcp.org/xml/ns/javaee"xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd http://xmlns.jcp.org/ Xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "version= "2.4"> <servlet> <Servlet-name>Dwr-invoker</Servlet-name> <Servlet-class>Org.directwebremoting.spring.DwrSpringServlet</Servlet-class> <Init-param> <Param-name>Debug</Param-name> <Param-value>False</Param-value> </Init-param> <Init-param> <Param-name>Crossdomainsessionsecurity</Param-name> <Param-value>False</Param-value> </Init-param> <Init-param> <Param-name>Allowscripttagremoting</Param-name> <Param-value>True</Param-value> </Init-param> <Load-on-startup>3</Load-on-startup> </servlet> <servlet-mapping> <Servlet-name>Dwr-invoker</Servlet-name> <Url-pattern>/dwr/*</Url-pattern> </servlet-mapping> </Web-app>
View Code
2. Applicationcontextsys.xml
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:dwr= "Http://www.directwebremoting.org/schema/spring-dwr"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-4.3.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context /spring-context-4.3.xsd Http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/ Schema/spring-dwr-3.0.xsd "> <Dwr:annotation-configID= "Dwrid"/> <Dwr:annotation-scanScanremoteproxy= "true"Base-package= "Com.ims.service.sys.impl" /></Beans>
View Code
3. Testbsimpl.java
package Com.ims.service.sys.impl; import Org.directwebremoting.annotations.RemoteMethod; import Org.directwebremoting.annotations.RemoteProxy; import Com.ims.service.sys.TestBS; @RemoteProxy (name = "Testbs" ) public Class Testbsimpl implements testbs{@ Remotemethod public String SayHello () { /span>return "hello!" ; }}
View Code
4. dwr.jsp
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en"><%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="UTF-8"%><HTML> <Head> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"> <title>DWR Access Test</title> <%@ include file="/common/basepath.jsp"%> </Head> <Body>~~~~~~~~~~~~~~~~~~~~~~dwr Access Test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<BR><BR> <Buttontype= "button"onclick= "SayHello ();">How are you doing</Button> <Scripttype= "Text/javascript"src= "Dwr/engine.js"></Script> <Scripttype= "Text/javascript"src= "Dwr/util.js"></Script> <Scripttype= "Text/javascript"src= "Dwr/interface/testbs.js"></Script> <Scripttype= "Text/javascript"> functionSayHello () {dwr.engine.beginBatch (); Testbs.sayhello (function(value) {alert (value); }); Dwr.engine.endBatch (); } </Script> </Body></HTML>
View Code
Four. Testing
Visit: http://localhost:8080/ims/test/dwr.do
Click the button, will go to the background of the SayHello function, the Return string popup dialog box
Spring and DWR integration implementation JS directly using Java code