1.首先在web.xml中配置如下代码:
<servlet>
<servlet-name>dwr</servlet-name>
<servlet-class>
org.directwebremoting.servlet.DwrServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
2.建立了一个Java类,简单代码如下:
public class TestDwr {
public String selectStr(String tempStr){
tempStr = tempStr+"嘿嘿";
return tempStr;
}
3.在WEB-INF目录下新建dwr.xml。测试代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr
PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
"http://getahead.org/dwr/dwr20.dtd" >
<dwr>
<allow>
<create javascript="gototest" creator="new">
<param name="class" value="org.mz.test.TestDwr"></param>
<include method="selectStr" />
</create>
</allow>
</dwr>
<param>节点,定义要发布的类别。
<include>节点,定义暴露的方法
4.建立页面代码:
<html>
<head>
<title>TestDwr</title>
<script type="text/javascript" src="dwr/interface/gototest.js"></script>
<script type="text/javascript" src="dwr/engine.js"></script>
<script type="text/javascript" src="dwr/util.js"></script>
<script type="text/javascript">
function init() {
var strUName = document.getElementById("username").value;
gototest.selectStr(strUName, checkname);
}
function checkname(isExist) {
alert(isExist);
}
</script>
</head>
<body>
<form action="" method="post">
<input type="text" id="username" onblur="init()"/>
<input type="text" id="password" onblur="init()"/>
</form>
</body>
</html>
5.OVER。。。。。。测试中。。。。。。
分享到:
评论