Cookie cookie=null;//不存在,创建cookie
if(cookie==null){
……
}//end if
你这里条件写错了,不是cookie==null,是cookies==null,按你那样写当然每次访问页面VisitTimes都变成1。这种问题自己细心调试就能发现,又不是什么疑难问题。
if(cookie==null){
……
}//end if
你这里条件写错了,不是cookie==null,是cookies==null,按你那样写当然每次访问页面VisitTimes都变成1。这种问题自己细心调试就能发现,又不是什么疑难问题。
if(cookies!=null){
for(int i=0; i<cookies.length; i++){
if(cookies[i].getName().equals("VisitTimes")){
String v=cookies[i].getValue();
int value=Integer.parseInt(v)+1;
cookies[i].setValue(Integer.toString(value));
cookie=cookies[i];
response.addCookie(cookie);
}//end if
}//end for
}//end if但是这里我通过cookie=cookies[i];这条语句进行了赋值,如果存在VisitTimes的cooike,那么在后面的if(cooike==null){ ... }也就不会执行了。