2011-06-25 68 views
2

我已發現此解決方案上索夫link 但我不得不它有兩個原因改變:如何在Tomcat 6設置的HttpOnly標誌在JSF 2.0應用

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

請糾正我,如果我錯了。謝謝你在前進

回答

3

在JSF 2.0,你可以這樣做:

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

這樣,你不需要做投給HttpServletResponse的。有關JSF的更多文檔,請檢查MyFaces Documentation Index

+0

謝謝。我希望這將有助於防止XSS攻擊 – Szajba

相關問題