DWR3 支持通过 Spring MVC 进行 URL 映射和控制器配置。主要涉及 web.xml、dwr-servlet.xml 以及 Spring 主配置文件的设置。
1. web.xml 配置
在 web.xml 中配置 DispatcherServlet,并映射到 /dwr/* 路径:
<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>
2. dwr-servlet.xml 配置
创建 dwr-servlet.xml 文件,定义 controller 及反向 Ajax 参数:
<?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">

