There are two ways to get the session id in JSF. One way through HttpSession and other way through cookies. Both these options are using FacesContext.
Option 1:
Option 2:
Option 1:
FacesContext fCtx = FacesContext.getCurrentInstance(); HttpSession session = (HttpSession) fCtx.getExternalContext().getSession(false); String sessionId = session.getId();
Option 2:
Map<String, Object> cookies = FacesContext.getCurrentInstance().getExternalContext().getRequestCookieMap(); Cookie cookie = (Cookie) cookies.get("JSESSIONID"); String sessionId = cookie.getValue();
0 Comments
Post a Comment