When using Servlet/JSP, we get HttpSession from HttpServletRequest, now that I develop an application using JSF/JPA/EJB, I don't know how to set attribute in session (for login exactly) and how to get them, any help.
Asked
Active
Viewed 1.9k times
1 Answers
12
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(true);
session.setAttribute("att", att);

NavinRaj Pandey
- 1,674
- 2
- 26
- 40
-
1what is the difference between getSession(true) and if we set false??? – user3923327 Sep 20 '14 at 17:50
-
1`getSession(true)` will create new if there is no session. `getSession(false)` will return `null` if there is no session – MD TAREQ HASSAN Apr 23 '19 at 08:49