How do I retrieve the session ID value inside a JSF managed bean?
Asked
Active
Viewed 2.8k times
3 Answers
44
FacesContext fCtx = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) fCtx.getExternalContext().getSession(false);
String sessionId = session.getId();

Yuval Adam
- 161,610
- 92
- 305
- 395

Damo
- 11,410
- 5
- 57
- 74
-
3I was just about to answer with almost the exact same code :) – Yuval Adam Apr 21 '09 at 13:30
1
You try
{
String uuidFc = FacesContext.getCurrentInstance().getExternalContext().getSessionId(true);
}
This line return the facesContext sessionId value

Subodh Joshi
- 12,717
- 29
- 108
- 202
-
This returns the servletcontext sessionid. And how does it differ from the other accepted answer? The true? Then why should be added to the answer – Kukeltje Feb 13 '19 at 15:31
0
You can also use the OmniFaces JSF utility library.
String sessionId = Faces.getSessionId();
Adding this as an answer, since it's highly likely that you will use this library, if you use JSF.

kozeljko
- 160
- 2
- 13