如果希望<代码>FacesContext可查,那么最好的位置是 afterPhase
of >PhaseID.RENDER_RESPONSE
within a PhaseListener
。 例如:
public class MyPhaseListener implements PhaseListener {
public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}
public void beforePhase(PhaseEvent event) {
// No operation here.
}
public void afterPhase(PhaseEvent event) {
FacesContext context = event.getFacesContext();
// Do your thing here with the FacesContext.
}
}
如果您不需要<代码>FacesContext,那么最好的位置就在chain.doFilter(request, response)
内。 例如:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
chain.doFilter(request, response);
// Do your thing here.
}