java类
/**
*@type_name: TestDwr
*@date: 2006-9-19
*@author scott_zhou
*/
package com.rain.dwr;
/**
*
*/
public class TestDwr {
public String getWord(String username){
return "Hello "+username;
}
}
web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="
http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
</web-app>
dwr.xml配置
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
"
http://www.getahead.ltd.uk/dwr/dwr10.dtd">
<dwr>
<allow>
<create creator="new" javascript="Test">
<param name="class" value="com.rain.dwr.TestDwr"/>
</create>
</allow>
</dwr>
HTML页面代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test.html</title>
<script type='text/javascript' src='/angry/dwr/interface/Test.js'></script>
<script type='text/javascript' src='/angry/dwr/engine.js'></script>
<script type='text/javascript' src='/angry/dwr/util.js'></script>
<script type="text/javascript">
function show(){
var name=DWRUtil.getValue("username");//使用getvalue方法得到id为username的值
Test.getWord(name,execute);//调用getWord方法,第一个参数为传递的值,最后一个参数为回调程序
//alert(word);
}
function execute(data){
DWRUtil.setValue("a",data); //调用setValue方法来设置值
DWRUtil.setValue("rst",data);
}
</script>
</head>
<body>
<INPUT type="text" id="username">
<INPUT type="button" value="提交" onclick="show()">
<INPUT type="text" id="rst">
<div id="a">
</div>
</body>
</html>
posted on 2006-09-19 15:04
周锐 阅读(177)
评论(0) 编辑 收藏 所属分类:
Ajax 、
Java