10

里面一个

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)

我想使用

FacesContext.getCurrentInstance().getExternalContext().getSession(false);

但我意识到,FacesContext.getCurrentInstance()回报null。我知道我可以((HttpServletRequest) req).getSession(false)改为使用会话,但我的具体问题是:为什么null方法中的面孔上下文doFilter()

我正在使用 MyFaces 1.1。

4

1 回答 1

13

FacesContext as an object is tied directly to the JSF request processing lifecycle and as a result is only available during a standard JSF (user-driven) request-response process. The actual object itself is stored in a thread that runs during the processing of a JSF request, vis-a-vis a ManagedBean.

But. BalusC has outlined some steps to get your hands on the object outside of the processing lifecycle here. :)

于 2013-01-18T08:28:26.103 回答