在我的应用程序中,我有一个 WebFilter。这个 Webfilter 应该检查一个 cookie。但是使用 FacesContext.getCurrentInstance() 会产生 Nullpointer 异常。我该如何解决这个问题?
网络过滤器:
@Inject
private CookieManager cm;
[...]
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if(cm.isDoCheck()){
cm.doCheck();
}
chain.doFilter(request, response);
}
[...]
执行 FacesContext.getCurrentInstance() 的 CookieManager:
[...]
private void doCheck(){
FacesContext context = FacesContext.getCurrentInstance();
Map<String, Object> cookies = context.getExternalContext().getRequestCookieMap();
Cookie cookie = (Cookie) cookies.get("frontend");
if(cookie != null){
setSessionHash(cookie.getValue());
}
}
[...]
context.getExternalContext().getRequestCookieMap();
给出了
StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException