Software Development

JSF – Get HTTP Session Attribute

This post demonstrates how to retrieve a attribute from an HTTP Session object in JSF 2.


Stuff used in this post.

  • JSF 2.2
    • javax.faces-2.2.8.jar
  • JDK 8

Using FacesContext


To access the HTTP Session object, we need to use the FacesContext to get an external context. JSF has its own context apart from the Servlet/JSP context which in this case is our “external context”.

The following codes look for an attribute named "loggedIn" in the HttpSession object. If the attribute exists, we set sessionData to that value. Otherwise, we set sessionData to "false".

This outputs:



For testing purposes, we use another URL to set the attribute "loggedIn" in the HttpSession object to "true".

If we click the same button in the previous page, the value is now "true".


Download the codes


Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like