前端 跨Area后Cookie无法访问

创建两个区域,一个是User,一个是Manage。

User区域有两个页面,index1,和index2

User区域:

  index1:负责写入cookie

  index2:负责读取cookie

Manage区域:

  index3:负责读取cookie

写入cookie的代码为:$.cookie("mystyle", "blue");

测试结果:index1 和 index2 都能访问到cookie,index3不能(跨了Area)

写入cookie的代码换成:$.cookie("mystyle", "blue", {path: "/"});

测试结果:当前域名下的所有页面都可以访问了

原因:cookie,默认不设置path的时候,只会在请求和servlet同路径的情况下才会携带cookie中存储的数据,包含同级目录和下级目录

原文:https://www.cnblogs.com/coderwjq/p/7064935.html

原文地址:https://www.cnblogs.com/guxingy/p/10437737.html