DWR高级主题之DWR与spring集成(使用springMVC,非注解的实例)

来源:互联网 发布:游族网络人数 编辑:程序博客网 时间:2024/05/09 20:21

DWR高级主题之DWR与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">  <display-name>DWR Sample App</display-name>  <description>DWR Sample App</description> <servlet>     <servlet-name>dwrSampleApp</servlet-name>     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>     <init-param>      <param-name>contextConfigLocation</param-name>        <param-value>          classpath:dwr3SampleAppSpringMVC.xml        </param-value>    </init-param>    <load-on-startup>1</load-on-startup>   </servlet>   <servlet-mapping>     <servlet-name>dwrSampleApp</servlet-name>     <url-pattern>/dwr/*</url-pattern>   </servlet-mapping> </web-app>

springMVC的配置文件:

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"       xmlns:aop="http://www.springframework.org/schema/aop"       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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd       http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">  <dwr:controller id="dwrController" debug="true" />  <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">    <property name="alwaysUseFullPath" value="true"/>    <property name="mappings">    <props>      <prop key="/dwr/**/*">dwrController</prop>    </props>    </property>  </bean>  <dwr:configuration>    <dwr:convert type="bean" class="org.uk.ltd.dwr.dev.model.Address" />  </dwr:configuration>  <bean id="dwrService" class="org.uk.ltd.dwr.dev.service.DWRService">    <dwr:remote javascript="dwrService">      <dwr:include method="getAddress" />       </dwr:remote>  </bean>  </beans>

java类:

package org.uk.ltd.dwr.dev.model;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.uk.ltd.dwr.dev.model.Address;public class DWRService {public DWRService() { }public Address getAddress() throws Exception {Address address = new Address();address.setStreet("2245 NW Overlook Drive");address.setCity("Portland");address.setState("Oregon");return address;}}

index.html

<html><head><title>DWR Dev</title><script type="text/javascript" src="/dwr3SampleAppSpringMVC/dwr/engine.js"></script><script type="text/javascript" src="/dwr3SampleAppSpringMVC/dwr/util.js"></script><script type="text/javascript" src="/dwr3SampleAppSpringMVC/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>DWR/Spring and Spring MVC</h3><a href="#" onclick="getDataFromServer(); return false;">Retrieve test data</a><br/></body></html>



原创粉丝点击