六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 38|回复: 0

DWR3基于Spring MVC配置Controller的方法

[复制链接]

升级  33.67%

83

主题

83

主题

83

主题

举人

Rank: 3Rank: 3

积分
301
 楼主| 发表于 2013-1-29 11:41:39 | 显示全部楼层 |阅读模式
DWR3 可以使用Spring MVC来进行url映射,配置如下:

web.xml

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

需要一个dwr-servlet.xml的文件:

<?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/aop http://www.springframework.org/schema/aop/spring-aop.xsd      
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">


    <!-- 将util.js和engine.js映射到下面的dwrController -->
    <dwr:url-mapping />

    <!-- debug开启 -->
    <dwr:controller id="dwrController" debug="true" >
        <!-- 如果有反向Ajax调用 -->
        <dwr:config-param name="activeReverseAjaxEnabled" value="true" />
    </dwr:controller>

</beans>

然后在Spring 的主配置加入如下配置,就可以使用DWR标注了

    <!-- 启用 annotation 配置模式 -->
    <dwr:configuration >
       <dwr:convert type="bean" class="org.feifei.*"></dwr:convert>
    </dwr:configuration>

    <!-- Spring容器中检查拥有@RemoteProxy 和 @RemoteMethod注解的类 -->
    <dwr:annotation-config>
    </dwr:annotation-config>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表