默认情况下,Glassfish v3不会在会话cookie上设置httpOnly标志(当使用request.getSession()
创建时)。
我知道,有一个方法javax.servlet.SessionCookieConfig.setHttpOnly()
,但我不确定,这是否是最好的方法,如果是,最好的位置是放那一行。
顺便说一句,当然它不能在servlet本身中完成(例如在init()中):
java.lang.IllegalStateException: PWC1426:
Unable to configure httpOnly session tracking cookie property for
servlet context /..., because this servlet context has already been initialized
通常,我更喜欢使用配置选项,例如在web.xml中。
发布于 2010-06-14 04:13:33
这是通过Servlet3.0 web.xml
(参见web-common_3_0.xsd
)支持的:
<web-app>
<session-config>
<cookie-config>
<!--
Specifies whether any session tracking cookies created
by this web application will be marked as HttpOnly
-->
<http-only>true</http-only>
</cookie-config>
</session-config>
</web-app>
发布于 2014-10-15 21:40:32
您还可以添加<secure>true</secure>
来增强安全性。
<session-config>
<cookie-config>
<http-only>true</http-only>
<secure>true</secure>
</cookie-config>
</session-config>
https://stackoverflow.com/questions/3033349
复制相似问题