什么是DWR?它有哪些功能? [中]
DWR(Direct Web Remoting)是一个WEB远程调用框架. 可以在客户端利用JavaScript直接调用服务端的Java方法并返回值给JavaScript DWR根据Java类来动态生成JavaScrip代码. 支持Dom Trees,支持Spring,支持commons-logging <?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="MsgPush">
<param name="class" value="com.middleware.dwr.MsgReverseAjax"/>
</create>
</allow>
</dwr>
方法里调用
public static void pusMessage(TE_MESSAGE_ALERT message){
String org_coad = message.getRECEIVE_ORG();
String af = "pushMessage";
String type = "null";
Map<String,String> map = new HashMap<String,String>();
Message m = null;
map.put("id",message.getMESSAGE_ID()+"");
map.put("event_id", message.getEVENT_ID());
map.put("type", message.getEVENT_TYPE());
map.put("title", message.getEVENT_TITLE());
map.put("org_coad", org_coad);
map.put("if_handle", message.getIF_HANDLE());
map.put("handle_id", message.getHANDLE_ID());
m = new Message(org_coad,type,af,map);
MsgReverseAjax mra = new MsgReverseAjax();
mra.update(m);
}
MsgReverseAjax.java 执行
package com.middleware.dwr;
import java.util.Date;
import java.util.List;
import org.directwebremoting.ScriptBuffer;
import org.directwebremoting.ScriptSession;
public class MsgReverseAjax {
private UScriptSessionCache ussc = UScriptSessionCache.getInstance();
public MsgReverseAjax() {
}
public void update(Message m) {
List<ScriptSession> list = ussc.all();
if (list != null && list.size() > 0) {
System.out.println("time : " + new Date().getTime() + " , push list "+list.size());
for (ScriptSession ss : list) {
String msg = m.getMesage();
ss.addScript(new ScriptBuffer()
.appendScript(m.getAjaxFunction())
.appendScript("(").appendData(msg)
.appendScript(");"));
}
}else{
System.out.println("no scriptsession in cache");
}
}
}
原文:http://www.cnblogs.com/pureEve/p/6428107.html