【问题标题】:Retrieving session ID value from a JSF request从 JSF 请求中检索会话 ID 值
【发布时间】:2010-10-20 19:52:47
【问题描述】:

如何在 JSF 托管 bean 中检索会话 ID 值?

【问题讨论】:

    标签: java session jsf


    【解决方案1】:
    FacesContext fCtx = FacesContext.getCurrentInstance();
    HttpSession session = (HttpSession) fCtx.getExternalContext().getSession(false);
    String sessionId = session.getId();
    

    【讨论】:

    • 我正准备用几乎完全相同的代码回答 :)
    【解决方案2】:

    你试试

    {
    String uuidFc = FacesContext.getCurrentInstance().getExternalContext().getSessionId(true);
    }
    

    此行返回 facesContext sessionId 值

    【讨论】:

    • 这将返回 servletcontext sessionid。它与其他公认的答案有何不同?真实的?那么为什么要添加到答案中
    【解决方案3】:

    您也可以使用OmniFaces JSF utility library

    String sessionId = Faces.getSessionId();
    

    添加这个作为答案,因为如果你使用 JSF,你很可能会使用这个库。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多