All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.lingkang.sessioncore.utils.CookieUtils Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy