这是一个简单的演示如何动态地更新网页 文本从一个web服务器。
演示效果如下图:
@H_403_10@
@H_403_10@
HTML源代码:
<p> Name: <input type="text" id="demoName"/> <input value="Send" type="button" onclick="update()"/> <br/> Reply: <span id="demoReply"></span> </p>
Javascript来源:
function update() { var name = dwr.util.getValue("demoName"); Demo.sayHello(name,function(data) { dwr.util.setValue("demoReply",data); }); }@H_403_10@
Java源代码:
package org.getahead.dwrdemo.simpletext; public class Demo { public String sayHello(String name) { return "Hello," + name; } }@H_403_10@ 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 creator="new" javascript="Demo"> <param name="class" value="org.getahead.dwrdemo.simpletext.Demo"/> </create> </allow> </dwr>