JAVA 读写Cookie
程序员文章站
2024-03-20 14:41:58
...
package com.hhsj.sso.utils;
import java.util.Objects;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CookieUtil {
private CookieUtil() {
}
public static void addCookie(HttpServletResponse response, String name, String value, int maxAge) {
Cookie cookie = new Cookie(name, value);
cookie.setPath("/");
cookie.setHttpOnly(true);
if (maxAge > 0) {
cookie.setMaxAge(maxAge);
}
cookie.setHttpOnly(Boolean.TRUE);
response.addCookie(cookie);
}
public static void removeCookie(HttpServletResponse response, String name) {
Cookie uid = new Cookie(name, (String)null);
uid.setPath("/");
uid.setMaxAge(0);
response.addCookie(uid);
}
public static String getValue(HttpServletRequest request, String cookieName) {
Cook
上一篇: 【小技巧】关于maven使用的小技巧