作者:mobiledu2502874233 | 来源:互联网 | 2023-05-19 02:16
参考资料:http:directwebremoting.orgdwrdocumentationserverintegrationspring.html和http:www.butter
参考资料:http://directwebremoting.org/dwr/documentation/server/integration/spring.html和http://www.butterdev.com/dwr/2008/02/dwr-20x-spring-2x-with-spring-mvc/
至于想使用基于注解的dwr配置可参考http://directwebremoting.org/dwr/documentation/server/integration/spring.html.
用了几天去了解dwr,真的没有感受到dwr的强大.我现在的理解就是在本地使用Javascript透明地远程调用服务器应用的java方法.现在好像用不上啊...至于什么无刷新页面的更新,由它去吧...
1.新建pom.xml,并导入此maven工程:
4.0.0
com.test
testdwr
war
1.0-SNAPSHOT
testweb Maven Webapp
http://maven.apache.org
UTF-8
3.2.7.RELEASE
org.apache.maven.plugins
maven-compiler-plugin
1.7
org.eclipse.jetty
jetty-maven-plugin
9.1.2.v20140210
200
/testdwr
80
60000
org.springframework
spring-webmvc
${spring.version}
com.fasterxml.jackson.core
jackson-databind
2.3.1
javax.servlet
javax.servlet-api
3.1.0
javax.servlet.jsp.jstl
javax.servlet.jsp.jstl-api
1.2.1
commons-logging
commons-logging
1.1.3
org.directwebremoting
dwr
3.0.M1
2.配置web.xml.要注意两个servlet-mapping的顺序.
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"
metadata-complete="true">
dispatcher
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:applicationContext.xml
1
dispatcher
/dwr/*
dispatcher
/
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
encodingFilter
/*
index.html
index.jsp
3.spring的配置文件applicationContext.xml.(变态的现在是http://directwebremoting.org/schema/spring-dwr-3.0.xsd不能加www,估计域名www.directwebremoting.org没有解析到部署站点的主机ip,造成http://www.directwebremoting.org/schema/spring-dwr/spring-dwr-3.0.xsd不能访问)
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.directwebremoting.org/schema/spring-dwr http://directwebremoting.org/schema/spring-dwr-3.0.xsd">
dwrController
text/html;charset=UTF-8
4.写上pojo,dwr的暴露service等
5.运行mvn jetty:run,在google浏览器输入http://localhost/testdwr/index.html,查看开发工具的console.顺便测试http://localhost/testdwr/user/save和http://localhost/testdwr/user/get是否正常.
源码:http://download.csdn.net/detail/xiejx618/6980795