在JSF PhaseListener中添加cookie [英] Adding cookie in JSF PhaseListener
本文介绍了在JSF PhaseListener中添加cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用JSF 1.1版的旧版应用程序
I have a legacy application using JSF version 1.1
我试图在所有响应中设置cookie,但是要通过 PhaseListener code>的实现,而不是通常的
Filter
,因为有具体的要求。
I am trying to set a cookie in all responses, but through a PhaseListener
implementation instead of usual Filter
because of specific requirement.
我做了类似的事情:
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。
However, when I am checking the responses in chrome dev console, I do not see this cookie.
我在做什么错了?
推荐答案
可能在RENDER_RESPONSE之后直到深夜,RENDER_RESPONSE才能正常工作。
after RENDER_RESPONSE is probably to late, before RENDER_RESPONSE should work fine.
这篇关于在JSF PhaseListener中添加cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文