设置cookie
if(cookieValue==null||cookieValue.equals("")) {cookieValue="-"+tid+"-";}
else{ cookieValue="-"+tid+cookieValue.replaceAll("-"+tid+"-","-");}
//out.println("cookieValue="+cookieValue);
cookie=new Cookie(cookieName, cookieValue);
cookie.setMaxAge(3600);
response.addCookie(cookie);
获得cookie
String cookieName="LatestViewType";
String cookieValue="";
Cookie cookies[]=request.getCookies();
Cookie cookie=null;
if(cookies!=null){
for(int i=0;i cookie=cookies[i];
if(cookie.getName().equalsIgnoreCase(cookieName)){
cookieValue=cookie.getValue();
break;
}
}
}
博客介绍了Cookie的设置与获取方法。设置时,根据cookie值情况进行处理并设置有效期;获取时,从请求中获取所有cookie,遍历查找指定名称的cookie并获取其值。
1910

被折叠的 条评论
为什么被折叠?



