Cookie常用方法封装Utils

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 }
View Code

 使用方法:

1 Cookie cookie = CookieUtils.findCookie(request.getCookies(), "history");
原文地址:https://www.cnblogs.com/enshrineZither/p/3368114.html