I create an HttpSession container as follows:
@SessionScoped @ManagedBean(name="userManager") public class UserManager extends Tools { ... public String login() { ... FacesContext context = FacesContext.getCurrentInstance(); session = (HttpSession) context.getExternalContext().getSession(true); session.setAttribute("id", user.getID()); session.setAttribute("username", user.getName()); ... System.out.println("Session id: " + session.getId());
And I have a SessionListener that should give me information about the created session:
@WebListener public class SessionListener implements HttpSessionListener { @Override public void sessionCreated(HttpSessionEvent event) { HttpSession session = event.getSession(); System.out.println("Session id: " + session.getId()); System.out.println("New session: " + session.isNew()); ... } }
How can I get the username attribute?
If I try to use System.out.println("User name: " + session.getAttribute("username")) , it throws java.lang.NullPointerException ..
gaffcz
source share