1、查询某个指定的cookie
1 package com.sun.etalk.cookie; 2 3 import javax.servlet.http.Cookie; 4 5 public class CookieUtils { 6 /** 7 * 在Cookie数组中查找指定name cookie 8 */ 9 public static Cookie findCookie(Cookie[] cookies, String name){ 10 if(cookies == null){ 11 return null; 12 }else{ 13 for (Cookie cookie : cookies) { 14 if(cookie.getName().equals(name)){ 15 return cookie; 16 } 17 } 18 return null; 19 } 20 } 21 }
使用方法:
1 Cookie cookie = CookieUtils.findCookie(request.getCookies(), "history");