【发布时间】:2014-07-21 13:17:38
【问题描述】:
我使用了 Servlet 3.0,我希望使用 HttpOnly 标志来保护我的 cookie。我的 web.xml 是
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<session-config>
<cookie-config>
<http-only>true</http-only>
<secure>true</secure>
</cookie-config>
</session-config>
</web-app>
我的 Servlet 是
response.setContentType("application/json");
PrintWriter pw = response.getWriter();
Cookie cookie = new Cookie("url", "google.com");
cookie.setMaxAge(60 * 60); //1 hour
response.addCookie(cookie);
pw.println("Cookies created");
我的 context.xml 是
<Context cookies="true" crossContext="true" useHttpOnly="true">
<SessionCookie httpOnly="true"/>
</Context>
但我可以从 Javascript 读取 cookie。有人可以帮帮我吗?
【问题讨论】:
-
你在使用Tomcat吗?哪个版本?
-
你的 context.xml 是什么?
-
我使用的是JBOSS 7,但它相当大吗?
-
是的,并非所有 Web 服务器的所有版本都实现 httponly
-
据我所知 Jboss7 支持它。我已经更新了我的问题
标签: java servlets cookies httponly