当前位置: 代码迷 >> Web前端 >> 怎么在AOM中怎么获取request,response,session
  详细解决方案

怎么在AOM中怎么获取request,response,session

热度:100   发布时间:2012-08-31 12:55:03.0
如何在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相关的东西。

  相关解决方案