1.web.xml中加入dwr配置如下:
<!-- dwr 配置 --> <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>
2.由spring接管dwr,配置spring的xml文件如下:
spring的xml中开头namespace加上drw标签配置
<?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" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 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-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" default-autowire="byName">
spring中配置dwr,如下:
<!-- dwr 配置 --> <!-- 注意这里新增加的dwr tag, 为使其生效,文件头中要声明namespace --> <dwr:configuration> <dwr:convert type="bean" class="com.myweb.modal.ibatis.Month" /> </dwr:configuration> <!-- 扫描读取注解加载的类 --> <dwr:annotation-scan scanRemoteProxy="true" base-package="com.myweb.service" /> <dwr:url-mapping /> <!-- 部署项目时, 请把debug设为false --> <dwr:controller id="dwrController" debug="true" />
3.配置dwr的service:
package com.myweb.service; import java.util.List; import org.directwebremoting.annotations.RemoteMethod; import org.directwebremoting.annotations.RemoteProxy; import org.directwebremoting.spring.SpringCreator; import org.springframework.beans.factory.annotation.Autowired; import com.myweb.modal.ibatis.Month; @RemoteProxy(creator=SpringCreator.class) public class TestDwrService { @Autowired private MonthService monthService; @RemoteMethod public List<Month> test(){ List<Month> months = monthService.findIMonths(); return months; } }
4.配置页面:
<!-- struts2不推荐使用JSTL,如果要使用el表达式,请注意加入isELIgnored="false" --> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%> <%@ include file="/common/taglib.jsp"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script type='text/javascript' src='${ctxPath}/dwr/engine.js'></script> <script type='text/javascript' src='${ctxPath}/dwr/util.js'></script> <script type='text/javascript' src='${ctxPath}/dwr/interface/TestDwrService.js'></script> </head> <body> <a href="javascript:testDwr();">测试dwr</a> </body> <script type="text/javascript"> function testDwr(){ TestDwrService.test(function(data){ var detail = ''; for(var i=0;i<data.length;i++){ detail = detail + data[i].name+"花费:"+data[i].total+"元\r\n" } alert(detail); }); } </script> </html>
相关推荐
spring使用annotation整合dwr笔记 spring使用annotation整合dwr笔记 spring使用annotation整合dwr笔记
spring整合DWR的一些配置问题,如下: 1、web.xml中加入dwr配置 2、由spring接管dwr,配置spring的xml文件 3、配置dwr的service 4、配置页面
源码 博文链接:https://callan.iteye.com/blog/166986
dwr与 spring整合 传对象的例子
使用spring 整合dwr的反推技术,可以运用于在线聊天的实现。
网络上Spring整合DWR comet 实现无刷新、多人聊天室 的代码整理,包含jar包,eclipse工程,直接导入即可运行。
整合spring3mvc+hibernate4+spring-security3+dwr3的架包
Spring 2中整合DWR 2 MSN:zhoujianguo_leo@hotmail.com
dwr2.0 spring 3.0 整合示例
此实例作为Spring整合dwr基础入门实例,是菜鸟开始的必备资料!
使用dwr+spring实现消息推送 。
配置整合DWR3.0和Spring2.5使用annotation注解
这是一个SPRING+DWR的整合项目.包括整合的三种方式,最彻底的整合是不需要配置DWRSERVLET+dwr.xml文件.使用annonation实现. 希望对你有用. 一起学习,一起进步...
精心整理的,dwr与目前流行框架spring和struts2的整合,值得一学
《疯狂Ajax讲义:Prototype/jQuery+DWR+Spring+Hibernate整合开发》是《基于J2EE的Ajax宝典》的第二版。《基于J2EE的Ajax宝典》面市近2年,作为Ajax领域最全面、实用的图书,一直深受读者的好评。全书主要分为三个...
Spring+Dwr+Hibernate整合项目,包括所需要的包和数据库
Spring与dwr的整合 环境是Myeclipse7.5 希望对大家有用!!!!
NULL 博文链接:https://605113068.iteye.com/blog/1731323
springMVC整合dwr完整例子,能让你快速掌握springMVC框架和DWR是如何工作