servlets - Java HttpOnly Flag -
i used servlet 3.0 , want secure cookies httponly flag. 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>
and 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");
my context.xml
<context cookies="true" crosscontext="true" usehttponly="true"> <sessioncookie httponly="true"/> </context>
but can read cookies javascript . can me?
the web.xml configures session-cookie.
you should add
cookie.sethttponly(true);
to servlet.
Comments
Post a Comment