top.lingkang.sessioncore.utils.CookieUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of final-session-core Show documentation
Show all versions of final-session-core Show documentation
final-session 一个轻量级分布式session框架
package top.lingkang.sessioncore.utils;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
/**
* @author lingkang
* Created by 2022/1/26
*/
public class CookieUtils {
public static String getCookieValue(String name, Cookie[] cookies) {
if (cookies == null)
return null;
for (Cookie cookie : cookies) {
if (name.equals(cookie.getName())) {
return cookie.getValue();
}
}
return null;
}
public static void addSessionIdToCookie(String name, String value, boolean addAge, long time, HttpServletResponse response) {
Cookie cookie = new Cookie(name, value);
cookie.setPath("/");
if (addAge)
cookie.setMaxAge((int) (time / 1000));
response.addCookie(cookie);
}
}