当前位置: 代码迷 >> Web前端 >> DWR2.0 调整Spring2.0
  详细解决方案

DWR2.0 调整Spring2.0

热度:280   发布时间:2012-10-20 14:12:48.0
DWR2.0 整合Spring2.0

1.jar包:

? spring2.5基本的jar包引入,(在http://yxwang0615.iteye.com/blog/967373中有笔记);

??dwr.jar;

? commons-pool-1.3.jar;

2.web.xml中加入dwr拦截器、监听器及自动加载spring配置文件的参数:

<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">
	
	 <!-- DWR2.0 BEGIN -->
   <servlet>
    <servlet-name>dwrInvoker</servlet-name>
    <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
    <init-param>
      <param-name>debug</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>classes</param-name>
    <param-value>java.lang.Object</param-value>
    </init-param>
    <init-param>
    	<param-name>crossDomainSessionSecurity</param-name>
    	<param-value>false</param-value>
    </init-param>
      
      <load-on-startup>4</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>dwrInvoker</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
  </servlet-mapping>
  <!-- DWR2.0 END -->
  <listener>
  	<listener-class>
  		org.springframework.web.context.ContextLoaderListener
  	</listener-class>
  </listener>
  <context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/applicationContext*.xml</param-value>
	</context-param>

	
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

3.?业务逻辑类及相关的实体类:

?

//User类:
public class User implements Serializable{
	private int id;
	private String uname;
	private String upass;
                getter and setter..
}

//UserManage类:
public class UserManager implements Serializable{
	
	public List getlist(){
		
		List users = new ArrayList();
		User u = null;
		for(int i = 0; i < 5; i++){
			u = new User();
			u.setId(i);
			u.setUname("name" + i);
			u.setUpass("pass" + i);
			System.out.println(i);
			users.add(u);
		}
		return users;
	}
         public boolean validate(String uname, String upass){
               if("admin".equals(uname)&& "admin".equals(upass)){
	    return true;
               }
              return false; 
         }
}

4.??spring配置文件,放在/WEB-INF/下:

<?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:aop="http://www.springframework.org/schema/aop"
	     xmlns:tx="http://www.springframework.org/schema/tx"
	     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="UserManager" class="com.wyx.test.UserManager">
	</bean>
</beans>

?5.dwr.xml:

<?xml version="1.0" encoding="UTF-8"?>
<dwr>
    <allow>
        <convert  converter="bean" match="com.wyx.test.User"></convert>
        
        <create creator="spring" javascript="UserManager">
			  <param name="beanName" value="UserManager"/>	
        </create>        
   </allow>
</dwr>

?

参考:http://wenku.baidu.com/view/c26248c58bd63186bcebbcad.html

  相关解决方案