Name

Cookie

Synopsis

The Cookie class provides servlets with an easy way to read, create, and manipulate HTTP-style cookies. Cookies provide a way to store a small amount of information on the client and are typically used for session tracking or storing user-configuration information. The getCookies() method of HttpServletRequest returns an array of Cookie objects. To set a new cookie on the client, a servlet creates a new Cookie object and uses the addCookie() method of HttpServletResponse. This must be done before sending any other content, since cookies are created within the HTTP header stream. The various methods of the Cookie class allow a servlet to set and get various attributes of a Cookie object, such as its path and domain.

                  Other Classes
public class Cookie implements Cloneable {
// Public Constructors
   public Cookie( String name, String value);  
// Property Accessor Methods (by property name)
   public String getComment();  
   public void setComment( String purpose);  
   public String getDomain();  
   public void setDomain( String pattern);  
   public int getMaxAge();  
   public void setMaxAge( int expiry);  
   public String getName();  
   public String getPath();  
   public void setPath( String uri);  
   public boolean getSecure();  
   public void setSecure( boolean flag);  
   public String getValue();  
   public void setValue( String newValue);  
   public int getVersion();  
   public void setVersion( int v);  
// Public Methods Overriding Object ...

Get Java Enterprise in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.