spring整合DWR步骤简单说明

1 篇文章 0 订阅
一、导入dwr包【dwr.jar】并在web.xml中添加如下代码
<listener>
<listener-class>org.directwebremoting.servlet.DwrListener</listener-class>
</listener>

<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>

<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>

<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>


二、编写service类,如下
package cn.com.songjy.service;

import org.springframework.stereotype.Service;

@Service("dwrService")
public class DwrService {

public String hello(String name){
return "你好," + name;
}

public String hello_1(String name){
return "Hello," + name;
}

public String getName(String name){

return name;
}

}


三、在WEB-INF目录下创建dwr.xml文件,如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN" "http://getahead.org/dwr/dwr30.dtd">

<dwr>

<allow>

<!-- DwrServiceJs是页面引用时要用到的名称 -->
<create creator="spring" javascript="DwrServiceJs">
<!-- dwrService是spring注入cn.com.songjy.service.DwrService类时名称 -->
<param name="beanName" value="dwrService" />
<!-- 对外公布方法列表,当须全部公布时,则无需配置include -->
<include method="hello"/>
<include method="hello_1"/>
</create>

</allow>

</dwr>


四、编写页面脚本测试【dwr.jsp】,如下
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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="<%=request.getContextPath()%>/dwr/engine.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/interface/DwrServiceJs.js"></script>
</head>
<script type="text/javascript">
DwrServiceJs.hello("张三", function(data){
alert(data);
});
</script>
<body>

</body>
</html>


最后访问【dwr.jsp】即可测试!

[url=http://coconut-zhang.iteye.com/blog/1447787]dwr反推技术[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值