读书人

spring + dwr annotation配备

发布时间: 2012-10-30 16:13:36 作者: rapoo

spring + dwr annotation配置
web.xml
和springmvc共用同一个DispatcherServlet:

<servlet><servlet-name>resource_management</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><load-on-startup>2</load-on-startup></servlet><servlet-mapping><servlet-name>resource_management</servlet-name><url-pattern>/dwr/*</url-pattern></servlet-mapping> 



dwrContext.xml
把dwr的请求转给dwrController处理:

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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-2.5.xsd            http://www.directwebremoting.org/schema/spring-dwr              http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd"><!--                <dwr:configuration />      -->    <dwr:configuration><dwr:convert type="bean" /><dwr:convert type="bean" /><dwr:signatures>   <![CDATA[]]>  </dwr:signatures></dwr:configuration><dwr:annotation-config />        <!-- Auto map .js files required in web page to DWR classes -->      <dwr:url-mapping />        <!-- Define DWR Controller in Spring container -->    <dwr:controller id="dwrController" debug="true" />        <!-- Adapter to use the plain Controller workflow interface with the generic org.springframework.web.servlet.DispatcherServlet.--><bean /> <bean value="1" /></bean><bean value="2" /></bean><bean value="3" /><property value="true" name="alwaysUseFullPath"></property><property name="mappings"><props><prop key="/dwr/**">dwrController</prop></props></property></bean> </beans>



Controller:

@Controller@RequestMapping("/xxx.do")@SessionAttributes({"aaa","bbb"})@RemoteProxy(creator = SpringCreator.class, name = "xxxddd")public class AddEventLogForm {        @RemoteMethodpublic List<EntityRow> getUsers(Integer id) {List<EntityRow> list = Service.getUsersById(id);return list;}}



jsp:
<script type='text/javascript' src='<c:url value="/dwr/engine.js"/>'></script><script type='text/javascript' src='<c:url value="/dwr/util.js"/>'></script><script type='text/javascript' src='<c:url value="/dwr/interface/xxxddd.js"/>'></script><script>//Use dwr to get users.function getxxxeee() {    xxxddd.getUsers(id, callbackMethod)}}//Display all the users.function callbackMethod(list) {        var ele = $("users");        ele.options.length=0;ele.options.add(new Option("Please Choose","-1"));for (var i=0; i<list.length; i++) {       ele.options.add(new Option(list[i].name, list[i].id));}}</script>


读书人网 >编程

热点推荐