getSession(true)正在返回null会话对象



Me使用jboss 5.1

我有一段代码如下,其中我将会话对象作为空

FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession)facesContext.getExternalContext().getSession(false);
if(session == null && facesContext.getExternalContext() !=null)
   session = (HttpSession)facesContext.getExternalContext().getSession(true);

不幸的是,即使我使用

session = (HttpSession)facesContext.getExternalContext().getSession(true);

会话对象返回为null,我该怎么办?

您的控制器实现了Filter吗?如果是这样,您可以从请求中获得您的会话:

HttpSession session = ((HttpServletRequest) request).getSession();

最新更新