TestDWR.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>第一个DWR测试</title>
<script type='text/javascript' src='dwr/interface/TestDWR.js'></script>
<script type='text/javascript' src='dwr/engine.js'></script>
<script type='text/javascript' src='dwr/util.js'></script>
</head>
<body>
<input id="user" type="text" >
<input type='button' value='提交' οnclick='hello();' >
<div id="result"></div>
</body>
</html>
<script>
function hello()
{
var user = $('user').value;
TestDWR.getUserName(user, callback);
}
function callback(msg)
{
DWRUtil.setValue('result', msg);
}
</script>
TestDWR.java
package com.comingnet.dwr;
public class TestDWR
{
public TestDWR()
{
}
public String getUserName(String username)
{
return "Hello,"+username+"的第一个dwr实例!";
}
}
dwr.xml
<dwr>
<allow>
<create creator="new" javascript="TestDWR">
<param name="class" value="com.comingnet.dwr.TestDWR"/>
</create>
</allow>
</dwr>