存过程
Cookie userstyleCookie = new Cookie("userstyle", stylepath);
userstyleCookie.setMaxAge(36000);
response.addCookie(userstyleCookie);
读取过程
String stylepath = "common";
Cookie[] cookieStyle = request.getCookies();
System.out.println(cookieStyle.length);
for(int i = 0; i<cookieStyle.length; i++){
Cookie cookie = cookieStyle[i];
if("userstyle".equals(cookie.getName())){
stylepath = cookie.getValue();
break;
}
}为什么读取不出cookie中的值
Cookie userstyleCookie = new Cookie("userstyle", stylepath);
userstyleCookie.setMaxAge(36000);
response.addCookie(userstyleCookie);
读取过程
String stylepath = "common";
Cookie[] cookieStyle = request.getCookies();
System.out.println(cookieStyle.length);
for(int i = 0; i<cookieStyle.length; i++){
Cookie cookie = cookieStyle[i];
if("userstyle".equals(cookie.getName())){
stylepath = cookie.getValue();
break;
}
}为什么读取不出cookie中的值
在存入值的时候需要
Cookie userstyleCookie = new Cookie("userstyle", stylepath);
userstyleCookie.setMaxAge(60*60*24*365);
userstyleCookie.setPath("/");
response.addCookie(userstyleCookie);我少了 userstyleCookie.setPath("/"); 这句话
谢谢大家的支持~~~~