如何在AOM中如何获取request,response,session

ExternalContext ec=FacesContext.getCurrentInstance().getExternalContext();
HttpServletRequest request=(HttpServletRequest)ec.getRequest();
HttpServletResponse response=(HttpServletResponse )ec.getResponse();

HttpSession session=(HttpSession)ec.getSession(true);或HttpSession session=(HttpSession)ec.getSession(false);

HttpSession session=(HttpSession)ec.getSession(true);当session存在时返回那个session当session不存在时创建一个新的session并返回
HttpSession session=(HttpSession)ec.getSession(false);当session存在时返回那个session当session不存在时返回null

其它的getApplicationMap() 、getInitParameter(java.lang.String name) 、getRequestParameterMap() 、getSessionMap() 、redirect(java.lang.String url) 等也都是这样的。
FacesContext类似于Servlet中的ServletContext,通过它可以得到Application、request、session、elContext、RenderKit、ViewRoot等一切与httpServlet相关的东西和JSF相关的东西。

你可能感兴趣的:(AOM session)