Java examples for javax.servlet.http:Cookie
servlet get User Name from Cookie
import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import org.apache.log4j.Logger; public class Main{ private final static Logger logger = Logger .getLogger(AuthenticationCookieUtils.class); public static final String ALA_AUTH_COOKIE = "ALA-Auth"; public static String getUserName(HttpServletRequest request) { return getCookieValue(request, ALA_AUTH_COOKIE); }/*from ww w.ja v a 2s.c o m*/ public static String getCookieValue(HttpServletRequest request, String name) { String value = null; Cookie cookie = getCookie(request, name); if (cookie != null) { value = cookie.getValue(); } return value; } public static Cookie getCookie(HttpServletRequest request, String name) { Cookie cookie = null; Cookie cookies[] = request.getCookies(); if (cookies != null) { for (Cookie c : cookies) { if (c.getName().equals(name)) { cookie = c; break; } } } if (cookie == null) { logger.debug("Cookie " + name + " not found"); } else { logger.debug("Cookie " + name + " found"); } return cookie; } }