美文网首页
js-cookie获取cookie值undefined的问题

js-cookie获取cookie值undefined的问题

作者: 憨厚老实的老赵 | 来源:发表于2018-05-16 09:47 被阅读0次

一开始设置了httponly为tru。
Tip:在cookie中设置了HttpOnly属性,那么通过js脚本将无法读取到cookie信息,这样能有效的防止XSS攻击。

 public static void setCookie(HttpServletResponse response, String key, String value, String domain, boolean httpOnly) {
        Cookie cookie = new Cookie(key, value);
        cookie.setPath("/");
        if (domain != null) {
            cookie.setDomain(domain);
        }

        cookie.setHttpOnly(httpOnly);
        response.addCookie(cookie);
    }

通过以下方式可以成功获取value值

const isHasAuth = Cookies.get('MANAGER_STATUS');
微信图片_20180516094636.png

HTTP字段打上勾的时候是不能获取cookie的

相关文章

网友评论

      本文标题:js-cookie获取cookie值undefined的问题

      本文链接:https://www.haomeiwen.com/subject/sqoudftx.html