public static String getCookieValue(HttpServletRequest request, String name) {
        if (request.getCookies() == null)
            return null;
        for (Cookie cookie: request.getCookies()) {
            if (cookie.getName().equals(name))
                return cookie.getValue();
        }
        return null;
    }