jsf-2 - 如何在 Tomcat 6 上的 JSF 2.0 应用程序中设置 HttpOnly 标志

标签 jsf-2 tomcat6 httponly

我在 Sof link 上找到了这个解决方案 但我不得不改变它有两个原因:

  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");

如有错误,请指正。提前谢谢您

最佳答案

在 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/

相关文章:

c# - 需要在 HttpWebResponse 中访问 HttpOnly cookie

jsf-2 - JSF @ViewScoped Bean 状态丢失

java - f :ajax listener not fired. 意外行为

servlets - ManagedBean 类中的 Java Faces ServletContext 对象

jsf-2 - JSF2、PrimeFaces 和 Highcharts - Ajax

javascript - 将外部 JavaScript 库添加到 Eclipse 项目?

linux - 在 lighttpd 中为 cookie 设置 http only 和 secure 标志

java - 在 WAR 文件中定义 Servlet 上下文

eclipse - 将 WebDSL 应用程序部署到 Tomcat v6.0 时出现的问题

tomcat - 带有 httpOnly 标志的 session cookie