配置多个Dwr并整合Spring、Struts

DWR整合Sturts配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC
    "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
    "http://getahead.org/dwr/dwr20.dtd">
    <!--
    creator置为"struts";
    param元素中的
    name值为formBean,
    value值为struts-config.xml配置文件中的form-bean元素的name值

     -->
<dwr>
<allow>
<create javascript="strutsDwr" creator="struts">
<param name="formBean" value="dwrForm"></param>
</create>
<convert converter="bean" match="com.dwr.struts.form.DwrForm"/>
</allow>
</dwr>


DWR整合Spring配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC
    "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
    "http://getahead.org/dwr/dwr20.dtd">
<!-- DWR整合Spring配置
creator属性的值可以是new,struts,spring、jsf、scripted、pageflow、none
因为此处是整合spring来做的,所以设置成"spring",
javascript="usercard" 表示实例转换成javascript语言后以usercard命名,
param元素的name属性值可以是class,beanName等,
此处用beanName,value得值是定义在applicationContext.xml中某个bean的id值。

  -->
<dwr>
<allow>
<create javascript="usercard" creator="spring">
<param name="beanName" value="usercard"></param>
</create>
<convert match="com.aptech.enterprise.entity.Usercard"
converter="bean">
</convert>
</allow>
</dwr>


以下这段代码为web.xml配置内容,所有Dwr配轩文件放置在WEB-INF目录下。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!--
DWR与Spring整合
初始化WebApplicationContext

-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

<!-- 配置DWR拦截器(一个Servlet对应多个DWR) -->
<servlet>
<servlet-name>dwr</servlet-name>
<servlet-class>
org.directwebremoting.servlet.DwrServlet
</servlet-class>
<!-- 构造new的DWR -->
<init-param>
<param-name>config-dwr</param-name>
<param-value>WEB-INF/dwr.xml</param-value>
</init-param>
<!-- 构造Spring的DWR -->
<init-param>
<param-name>config-usercard</param-name>
<param-value>WEB-INF/usercardDwr.xml</param-value>
</init-param>
<!-- 构造Struts的DWR -->
<init-param>
<param-name>config-strutsDwr</param-name>
<param-value>WEB-INF/StrutsDwr.xml</param-value>
</init-param>
<!-- 配置DWR调试参数 -->
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>logLevel</param-name>
<param-value>DEBUG</param-value>
</init-param>
</servlet>
<!-- 结束DWR配置 -->

<!-- Struts拦截器配置 -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
         <!-- 过滤器映射-->
<servlet-mapping>
<servlet-name>dwr</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

你可能感兴趣的:(spring,Web,xml,struts,DWR)