How to integrate the three frameworks I'm not going to say that many of the great gods in Csdn have a detailed integration blog.
Because we manage struts2 and hibernate with spring, we just need to integrate spring with DWR.
First of all we need to Dwr.jar I use the latest DWR3, previously tested DWR2 is also successful.
First put our Dwr.jar in the project Lib directory, and then in the same level of Web. XML directory under a new dwr.xml.
This is my dwr.xml configuration.
<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE dwr Public "-//getahead limited//dtd Direct Web Remoting 3.0//en" "Http://getahead.org/dwr/dwr30.dtd" > <dw R> <allow> <!--list to the page is the array. Map to the page, just go to rtu["field name", as queried from the database, remember the field name Capital---<convert converter= "Array" match= "*"/> <con Vert converter= "Array" match= "[[*"/> <convert converter= "collection" match= "Java.util.Collection"/> <!--traditional DWR-to-<create javascript= "courseaction" creator= "Spring" > <param name= "Beanname" value= "courseaction"/> </create>//JavaBean <con you need Vert converter= "Bean" match= "Com.jxust.bean.Chapter" > </convert> <convert converter= "Bean" match= "C Om.jxust.bean.Course "> </convert> <convert converter=" Bean "match=" com.jxust.service.serviceImpl.Vi Deoserviceimpl "> </convert> </allow> <signatures> <! [cdata[import Java.util.Map; Import java.util.List; ]]> </signatures> </dwr>
Then add this code to Web. xml
<!--dwr configuration-<servlet> <servlet-name>dwr-invoker</servlet-name> <servlet-class> ; Org.directwebremoting.servlet.DwrServlet </servlet-class> <init-param> <param-name>c Onfig-dwr</param-name> <param-value>/WEB-INF/dwr.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>false</param-val ue> </init-param> <init-param> <param-name>activereverseajaxenabled</param-name > <param-value>true</param-value> </init-param> <init-param> <pa ram-name> Initapplicationscopecreatorsatstartup </param-name> <param-value>t rue</param-value> </init-param> <init-param> <param-name>maxwaitafterwrite</ Param-name> <param-value>500</param-value> </init-param> <init-param> <PARAM-NAME>ALLOWGETFO Rsafaributmakeforgeryeasier</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>crossDomainSessionSecurity</param-name> <param-val ue>false</param-value> </init-param> <load-on-startup>2</load-on-startup> </SERVL et> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/dwr/* </url-pattern> </servlet-mapping>
This is used to configure the DWR.
Then introduce the/dwr/util.js,/dwr/engine.js, and Java methods that you want to manipulate on the DWR page you're introducing. I'm using the method that I introduced in action/dwr/interface/courseaction.js
<script type= ' text/javascript ' src= "<s:url value= '/dwr/util.js '/>" ></script> <script type= ' Text/javascript ' src= ' <s:url value= '/dwr/engine.js '/> ' ></script> <script type= ' Text/javascript ' src= "<s:url value= '/dwr/interface/courseaction.js '/>" ></script>
I've tested the two tool classes like DWR that can't be placed behind the action method, and if there's an error, ask the great God to correct it.
Here is the complete code for my page
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><% @taglib prefix= "s" uri= "/struts-tags" %><%string path = Request.getcontextpath (); String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
Just put the Java code out, too.
DWR Two-level linkage public set<chapter> getchapterlist (String name) throws exception{System.out.println ("ASDFASD"); Course course=courseservice.findbytitle (name); Getchapterlist=course.getcoursechapter (); return getchapterlist; }
List of Getter, setter method omittedSTRUTS2+SPRING+HIBERNATE+DWR3 implementation of the drop-down box two-level linkage