DWR3与spring集成(不使用springMVC,但使用注解的实例)

web.xml
    <?xml version="1.0" encoding="ISO-8859-1"?>  
    <!DOCTYPE web-app PUBLIC  
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"  
        "http://java.sun.com/dtd/web-app_2_3.dtd">  
      
    <web-app id="dwr_dev">  
      
      <listener>  
         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
       </listener>  
       <context-param>  
         <param-name>contextConfigLocation</param-name>  
         <param-value>  
           classpath:dwr3SampleAppSpring3AnnotNonSpringMVC.xml  
         </param-value>  
       </context-param>  
      
       <servlet>  
         <servlet-name>dwr</servlet-name>  
         <servlet-class>org.directwebremoting.spring.DwrSpringServlet</servlet-class>  
         <init-param>  
           <param-name>debug</param-name>  
           <param-value>true</param-value>  
         </init-param>  
       </servlet>  
       <servlet-mapping>  
         <servlet-name>dwr</servlet-name>  
         <url-pattern>/dwr/*</url-pattern>  
      </servlet-mapping>   
    </web-app>  

spring的bean配置文件
    <?xml version="1.0" encoding="UTF-8"?>  
    <beans xmlns="http://www.springframework.org/schema/beans"  
           xmlns:context="http://www.springframework.org/schema/context"  
           xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"  
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd  
           http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">  
        
       <dwr:configuration />     
       <dwr:annotation-scan base-package="org.uk.ltd.dwr.dev" scanDataTransferObject="true" scanRemoteProxy="true"/>     
    </beans>  

java文件
    package org.uk.ltd.dwr.dev.model;  
      
    import org.directwebremoting.annotations.DataTransferObject;  
      
    @DataTransferObject  
    public class Address {  
        private String street;  
        private String street2;  
        private String city;  
        private String state;  
          
        public String getStreet() {  
            return street;  
        }  
        public void setStreet(String street) {  
            this.street = street;  
        }     
        public String getStreet2() {  
            return street2;  
        }     
        public void setStreet2(String street2) {  
            this.street2 = street2;  
        }  
        public String getCity() {  
            return city;  
        }     
        public void setCity(String city) {  
            this.city = city;  
        }     
        public String getState() {  
            return state;  
        }     
        public void setState(String state) {  
            this.state = state;  
        }     
    }  

    package org.uk.ltd.dwr.dev.service;  
      
    import org.directwebremoting.annotations.RemoteMethod;  
    import org.directwebremoting.annotations.RemoteProxy;  
    import org.uk.ltd.dwr.dev.model.Address;  
      
    @RemoteProxy(name="dwrService")  
    public class DWRService {  
          
        public DWRService() { }  
          
        @RemoteMethod  
        public Address getAddress() throws Exception {  
            Address address = new Address();          
            address.setStreet("2245 NW Overlook Drive");  
            address.setCity("Portland");  
            address.setState("Oregon");  
            return address;  
        }  
          
        @RemoteMethod  
        public void printAddress() {  
            System.out.println("Printing");  
        }  
    }  

    <html>  
        <head>  
            <title>DWR Dev</title>  
            <script type="text/javascript" src="/dwr3SampleAppSpring3AnnotNonSpringMVC/dwr/engine.js"></script>  
            <script type="text/javascript" src="/dwr3SampleAppSpring3AnnotNonSpringMVC/dwr/util.js"></script>  
            <script type="text/javascript" src="/dwr3SampleAppSpring3AnnotNonSpringMVC/dwr/interface/dwrService.js"></script>     
            <script>  
                function getDataFromServer() {  
                  dwrService.getAddress({  
                    callback: getDataFromServerCallBack  
                  });  
                }  
                function getDataFromServerCallBack(dataFromServer) {  
                  alert(dwr.util.toDescriptiveString(dataFromServer, 3));  
                }  
            </script>  
        </head>  
        <body>  
            <h3> 3.x/Spring 3.x with Annotations and Spring MVC</h3>  
            <a href="#" οnclick="getDataFromServer(); return false;">Retrieve test data</a><br/>  
        </body>  
    </html>  



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值