public class CookieUtil { //增加 public static void addCookie(HttpServletResponse response,String name,String value,int maxAge){ Cookie cookie=new Cookie(name, value); cookie.setPath("/"); if(maxAge>0){ cookie.setMaxAge(maxAge); } response.addCookie(cookie); } //查询 public static String getCookie(HttpServletRequest request,String cookieName){ Cookie cookies[]=request.getCookies(); if(cookies!=null){ for (Cookie cookie:cookies){ if(cookie.getName().equals(cookieName)){ return cookie.getValue(); } } } return null; } //删除 public static void removeCookie(HttpServletResponse response,String name){ Cookie cookie=new Cookie(name,null); cookie.setPath("/"); cookie.setMaxAge(0); response.addCookie(cookie); } }
cookie的工具类
最新推荐文章于 2024-02-22 09:25:14 发布