web.xml中的class文件为:org.directwebremoting.servlet.DwrServlet
java代码为:
public class DwrPush{
public void send(String msg){
WebContext webContext=WebContextFactory.get();
Collection sessions=webContext.getAllScriptSessions();
ScriptBuffer sb=new ScriptBuffer();
sb.appendScript("callback(");
sb.appendScript(msg);
sb.appendScript(")");
Util util=new Util(sessions);
util.addScript(sb);
System.out.println(sb);
}
}
主要代码为:
$(document).ready(function() {
dwr.engine.setActiveReverseAjax(true);
$("#sign").click(function() {
DwrPush.send($("#msg").val());
});
});
function callback(msg) {
$("#ul").html($("#ul").html() + "
" + msg)
}
style="height: 60px; font-size: 35px" />