Here is a snippet to show how can we get the HttpSession, HttpServletRequest in JSF. Set the attribute in the session or get a parameter from session.
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
HttpSession httpSession = request.getSession(false);
// To get the attribute
String testParam= (String) httpSession.getAttribute("testParam");
// To set the param
httpSession.setAttribute("testParam", "testValue");
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
HttpSession httpSession = request.getSession(false);
// To get the attribute
String testParam= (String) httpSession.getAttribute("testParam");
// To set the param
httpSession.setAttribute("testParam", "testValue");
No comments:
Post a Comment