【问题标题】:how to set and get HttpSession using JSF/Bean (@named) [duplicate]如何使用 JSF/Bean(@named)设置和获取 HttpSession [重复]
【发布时间】:2014-09-20 17:41:38
【问题描述】:

使用 Servlet/JSP 时,我们从 HttpServletRequest 获取 HttpSession,现在我使用 JSF/JPA/EJB 开发应用程序,我不知道如何在会话中设置属性(准确用于登录)以及如何获取它们,任何帮助。

【问题讨论】:

    标签: jsf session


    【解决方案1】:
    FacesContext facesContext = FacesContext.getCurrentInstance();
    HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(true);
    session.setAttribute("att", att);
    

    【讨论】:

    • getSession(true) 和如果我们设置为false有什么区别???
    • 如果没有会话,getSession(true) 将创建新的。如果没有会话,getSession(false) 将返回 null
    猜你喜欢
    • 2018-02-15
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 2017-06-29
    • 2017-07-17
    • 2017-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多