标签:put ima com logo servlet 项目 red get ret
一、从request中读出cookies集合,然后封装成map,为的是能够直接通过name得到相应的cookie即get方法
public static Cookie get(HttpServletRequest request,
String name) {
Map<String, Cookie> cookieMap = readCookieMap(request);
if (cookieMap.containsKey(name)) {
return cookieMap.get(name);
}else {
return null;
}
}
/**
* 将cookie封装成Map
* @param request
* @return
*/
private static Map<String, Cookie> readCookieMap(HttpServletRequest request) {
Map<String, Cookie> cookieMap = new HashMap<>();
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie: cookies) {
cookieMap.put(cookie.getName(), cookie);
}
}
return cookieMap;
}
二、在SellUserController类中的logout方法中调用CookieUtil.get()读取cookie
然后清除redis和cookie
spring boot项目之登出删除缓存session至redis和cookies
标签:put ima com logo servlet 项目 red get ret
原文地址:https://www.cnblogs.com/bozzzhdz/p/9665305.html