日期:2014-05-18 浏览次数:20798 次
public class TestMsg {
public void sendMsg(String userid,String message){
final String userId = userid;
final String autoMessage = message;
//过滤器
ScriptSessionFilter filter = new ScriptSessionFilter() {
public boolean match(ScriptSession scriptSession) {
String tag = (String)scriptSession.getAttribute("userId" );
System. out.println(tag);
System.out.println("userId.equals(tag)="+userId.equals(tag));
return userId.equals(tag);
}
};
Runnable run = new Runnable(){
private ScriptBuffer script = new ScriptBuffer();
public void run() {
//设置要调用的 js及参数
System.out.println("----------------run----------------");
script.appendCall( "showMessage", autoMessage);
//得到所有ScriptSession
Collection<ScriptSession> sessions = DWRScriptSessionListener.getScriptSessions();
//遍历每一个ScriptSession
for (ScriptSession scriptSession : sessions){
System.out.println("for (ScriptSession scriptSession : sessions)");
scriptSession.addScript( script);
}
&n