日期:2014-05-17  浏览次数:20822 次

dwr+spring整合问题
applicationContext.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:p="http://www.springframework.org/schema/p"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
  <bean id="impl" class="test.DWRimpl"></bean>
  <bean id="dwrtest" class="test.DWRtest" scope="prototype">
  <property name="bean" ref="impl"></property>
  </bean>
</beans>

dwr.xml
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" "http://www.getahead.ltd.uk/dwr/dwr10.dtd"> 
<dwr> 
<allow> 
<!--javascript="前台引用的函数名" creator="spring"指定让Spring代理 name="beanName"固定 value的值为Spring配置文件的bean的id值 -->
<create creator="spring" javascript="Test" >  
<param name="beanName" value="dwrtest"/>
</create> 
<!--配置dwr交互 中所用到的bean实类 -->
<convert converter="bean" match="test.TestBean">
</convert>
</allow> 
</dwr>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
 xmlns="http://java.sun.com/xml/ns/javaee" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <!-- Spring配置 指定spring配置文件位置-->
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml</param-value>
 </context-param>
  <!-- 开启监听 -->  
  <listener>  
  <listener-class>
  org.springframework.web.context.ContextLoaderListener</listener-class>  
  </listener>
 <!-- 配置DWR -->  
 <servlet> 
<servlet-name>dwr-invoker</servlet-name> 
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class> 
</servlet> 
<servlet-mapping> 
<servlet-name>dwr-invoker</servlet-name> 
<url-pattern>/dwr/*</url-pattern> 
</servlet-mapping> 
  <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

applicationContext.xml,dwr.xml,web.xml三文件放在WebRoot/WEB-INF下


DWRimpl.java
Java code

package test;
import java.util.ArrayList;
import java.util