日期:2014-05-17  浏览次数:20862 次

解释一下这段关于cookie的代码什么意思
Cookie cookies[] = request.getCookies();
  if (cookies != null && cookies.length > 0) {
int length = cookies.length;
for (int i = 1; i < length; i++) {
cookies[i].setMaxAge(0);
// cookies[i].setValue(null);这两句注释了
//cookies[i].setPath("/wap");
response.addCookie(cookies[i]);
}
  }  
  cookies = request.getCookies();

------解决方案--------------------
Java code

Cookie cookies[] = request.getCookies(); //定义了一个cookie数组
  if (cookies != null && cookies.length > 0) {  //如果数组不为空,进入大括号内
int length = cookies.length;   //获得cookie数组的长度并赋值给length
for (int i = 1; i < length; i++) {   //开始遍历
cookies[i].setMaxAge(0);   //定义每个遍历出来的cookie的生命周期为0
 cookies[i].setValue(null); //定义每个遍历出来的cookie的value值为null
 cookies[i].setPath("/wap"); //定义每个遍历出来的cookie的访问路径
response.addCookie(cookies[i]);  //封装并传入到response中
}
  }   
  cookies = request.getCookies();