2

我在 Sof链接上找到了这个解决方案, 但我不得不从两个原因改变它:

  1. 没有 .getFacesContext() 函数
  2. 我没有特定的 cookie 文件(见 ourcookiename=yourcookievalue 行)

我的代码如下所示:

FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
response.addHeader("Set-Cookie", "; HTTPOnly");

原始代码

FacesContext facesContext = FacesContext.getCurrentInstance().getFacesContext();   
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();    
response.addHeader("Set-Cookie", "yourcookiename=yourcookievalue; HTTPOnly");

如果我错了,请纠正我。先感谢您

4

1 回答 1

5

在 jsf 2.0 中,您可以这样做:

FacesContext facesContext = FacesContext.getCurrentInstance();
facesContext.getExternalContext().addResponseHeader("Set-Cookie", "; HTTPOnly");

这样,您不需要对 HttpServletResponse 进行强制转换。有关 JSF 的更多文档,请查看MyFaces 文档索引

于 2011-06-25T02:33:00.577 回答