STRUTS2+SPRING+HIBERNATE+DWR3 implementation of the drop-down box two-level linkage

Source: Internet
Author: User

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&gt          ; 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> &LT;PARAM-NAME&GT;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> &LT;/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 omitted

STRUTS2+SPRING+HIBERNATE+DWR3 implementation of the drop-down box two-level linkage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.