我有一个使用JSF 1.1版的旧版应用程序
我正尝试在所有响应中设置cookie,但是由于特定要求,因此通过PhaseListener
实现而不是通常的Filter
设置
我做了类似的事情:
public class MyPhaseListener implements PhaseListener {
public PhaseId getPhaseId() {
return PhaseId.ANY_PHASE;
}
public void beforePhase(PhaseEvent event) {
}
public void afterPhase(PhaseEvent event) {
if (event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
HttpServletResponse httpResponse = (HttpServletResponse) FacesContext
.getCurrentInstance().getExternalContext().getResponse();
int cookieValue = 100;
Cookie cookie = new Cookie("myCookie", "" + cookieValue);
cookie.setPath("/");
httpResponse.addCookie(cookie);
}
}
}
但是,当我在chrome开发者控制台中检查响应时,没有看到此cookie。
我在做什么错了?
答案 0 :(得分:0)
在RENDER_RESPONSE之后可能要晚了,而在RENDER_RESPONSE应该可以正常工作之前。