本帖最后由 arborous 于 2009-07-16 09:51:46 编辑

解决方案 »

  1.   

    自己先顶下
    在DWR2中   org.directwebremoting.proxy.dwr.Util; 
    用这个的时候
     ScriptSession session = this.getScriptSession(receiverid, request);   
     Util util = new Util(session);   
     util.setValue("msg", msg);   
    这样就会把消息发送给指定的用户了,而不是所有的用户
      

  2.   

    最近也在做这个,正愁怎么解决呢。
    我的需求是,后台有线程一直在跑,如果有新消息,要主动推送给相应的用户。
    现在遇到的问题是怎么把登录的用户与Scriptsession绑定。
    页面不传request给后台线程。
      

  3.   

    不知楼主解决没有!最近看到一个好的文档// 推给所有用户
    Browser.withAllSessions(new Runnable() {
    public void run() {
    Util.removeAllOptions("users");
    Util.addOptions("users", users, "name");
    Util.removeAllOptions("receiver");
    Util.addOptions("receiver", users, "name");
    }
    });
    // 推给指定用户
    Browser.withCurrentPageFiltered(new ScriptSessionFilter() {
    public boolean match(ScriptSession session) {
    if (session.getAttribute("user") == null)
    return false;
    else
    return ((User) session.getAttribute("user")).getName()
    .equals(receiverid);
    }
    }, new Runnable() {
    public void run() {
    Collection<ScriptSession> colls = Browser.getTargetSessions();
    for (ScriptSession scriptSession : colls) {
    scriptSession.addScript(initFunctionCall(
    "dwr.util.setValue", "sender", sender));
    scriptSession.addScript(initFunctionCall(
    "dwr.util.setValue", "msg", msg));
    }
    }
    });