我在 Sof link 上找到了这个解决方案 但我不得不改变它有两个原因:
- 没有 .getFacesContext() 功能
- 我没有特定的 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");
如有错误,请指正。提前谢谢您
最佳答案
在 jsf 2.0 中你可以这样做:
FacesContext facesContext = FacesContext.getCurrentInstance();
facesContext.getExternalContext().addResponseHeader("Set-Cookie", "; HTTPOnly");
这样,您就不需要对 HttpServletResponse 进行强制转换。有关 JSF 的更多文档,请查看 MyFaces Documentation Index .
关于jsf-2 - 如何在 Tomcat 6 上的 JSF 2.0 应用程序中设置 HttpOnly 标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6475196/