Java examples for Servlet JSP:Cookie
Searches for a cookie within a HttpServletRequest.
import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; public class Main{ /**//from www .java 2 s . c o m * Searches for a cookie within a HttpServletRequest. * * @param name the name of the cookie. * @param request the HttpServletRequest to find the cookie on. * @return the cookie */ public static Cookie getCookieForName(String name, HttpServletRequest request) { if (request.getCookies() == null) { return null; } for (Cookie cookie : request.getCookies()) { if (cookie.getName().equalsIgnoreCase(name)) { return cookie; } } return null; } }