我是 DWR 的初学者。根据(http://directwebremoting.org/dwr-demo/simple/text.html)中的教程,我将 dwr 脚本放置在我的 html 文件中。但是当我运行应用程序时,它会显示以下消息。
ReferenceError: dwr is not defined
[Break On This Error]
var name = dwr.util.getValue("demoName");
我的 HTML 文件是:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type='text/javascript' src='/dwr/engine.js'>
</script>
<script type='text/javascript' src='/dwr/util.js'>
</script>
<title>Hello</title>
<script type="text/javascript">
function update() {
var name = dwr.util.getValue("demoName");
Demo.sayHello(name, function(data) {
dwr.util.setValue("demoReply", data);
});
}
</script>
</head>
<body>
<p>
Name: <input type="text" id="demoName" /> <input value="Send"
type="button" onclick="update()" /> <br /> Reply: <span
id="demoReply"></span>
</p>
</body>
</html>
我的 dwr.xml 文件是:
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN"
"http://getahead.org/dwr/dwr30.dtd">
<dwr>
<allow>
<create creator="new" javascript="Demo">
<param name="class" value="com.dwr.my.Demo" />
</create>
</allow>
</dwr>
类文件是Demo.java
package com.dwr.my;
public class Demo {
public String sayHello(String name) {
return "Hello, " + name;
}
}