我尝试使用从 javascript 获取 cookie 到 servlet
请求.getcookie()
方法。但我发现该值为空。
有没有办法从 javascript 获取 cookie 到 servlet?
我尝试使用从 javascript 获取 cookie 到 servlet
请求.getcookie()
方法。但我发现该值为空。
有没有办法从 javascript 获取 cookie 到 servlet?
尝试这个
Cookie[] cookies = request.getCookies();
for (int i = 0; i < cookies.length; i++) {
Cookie c = cookies[i];
c.getName() //cookie name
c.getValue() //cookie value
}
尝试这个
Cookie[] cookie = request.getCookies();
if(cookie != null && cookie.length > 0) {
System.out.println("CkInfo");
for(int i = 0;i < cookie.length; ++i) {
System.out.println("["+i+"] info");
System.out.println("Name: "+cookie[i].getName());
System.out.println("Comment: "+cookie[i].getComment());
System.out.println("Domain: "+cookie[i].getDomain());
System.out.println("MaxAge: "+cookie[i].getMaxAge());
System.out.println("Path: "+cookie[i].getPath());
System.out.println("Value: "+cookie[i].getValue());
}
}
for (Cookie c : request.getCookies()) {
if("myCookieName".equals(c.getName()) {
System.out.println(c.getValue());
}
}