请教个dwr的问题

怎么从ScriptSession取得当前用户,实现向特定的用户发送脚本? 下面是我的代码,要怎么改造?
FacesContext facesContext = FacesContext.getCurrentInstance();
ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
ServerContext sctx = ServerContextFactory.get(servletContext);
Collection sessions = sctx.getAllScriptSessions();
Util pages = new Util(sessions);
pages.addFunctionCall("initD", subject, "im.xhtml?users=" + java.net.URLEncoder.encode(users));

1个回答

[code="java"]
/**

  • 根据用户id获得指定用户的页面脚本session
  • @param userid
  • @param request
  • @return */ @SuppressWarnings("unchecked") public ScriptSession getScriptSession(String userid, HttpServletRequest request) { ScriptSession scriptSessions = null; Collection sessions = new HashSet(); sessions.addAll(ServerContextFactory.get(request.getSession().getServletContext()).getScriptSessionsByPage("/chat/index.jsp")); for (ScriptSession session : sessions) { String xuserid = (String) session.getAttribute("userid"); if (xuserid != null && xuserid.equals(userid)) { scriptSessions = session; } } return scriptSessions; } [/code]
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!