All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class WebSite.Servlet.Cookie

java.lang.Object
   |
   +----WebSite.Servlet.Cookie

public final class Cookie
extends Object

The Cookie class implements objects that represent state-management "cookies". The Cookie class supports both the functionality described in the Netscape Cookie Specification and the newer standards-track RFC 2109 State Management cookies. Under RFC 2109, a request or response may contain more than one cookie with the same name, differing only in their path or domain attributes. Therefore the WebSite.Servlet package stores the request and response cookies in Vectors instead of Hashtables. This makes it more time-consuming to locate a particular cookie or set of cookies (with the same name), as a Cookie cannot be fetched by its name, since names are not unique. At the time of release, there is work in progress to revise RFC 2109 based on implementation experience. The internet draft describing this as of February, 1998 is HTTP State Management Mechanism. As soon as these changes have reached RFC level, O'Reilly will issue a revised set of WebSite.Servlet classes to implement the new formats.

See Also:
Request, Response

Variable Index

 o comment
A comment which can be displayed to the client user when the cookie is received by the browser.
 o domain
The domain atrribute of the cookie.
 o FROM_REQUEST
A convenience value to indicate that the Cookie object should be constructed from a string of the format used in requests (with the Cookie: header).
 o FROM_RESPONSE
A convenience value to indicate that the Cookie object should be constructed from a string of the format used in responses (with the Set-Cookie: header).
 o maxAge
The maximum lifetime of the cookie in seconds.
 o name
The name of the cookie.
 o path
The path attribute of the cookie.
 o secure
If true the cookie is sent by the browser only if it is using an encrypted (SSL) channel.
 o value
The value of the cookie.
 o version
The version of the cookie.

Constructor Index

 o Cookie(String, int)
Constructs a Cookie object from a string representation of a cookie.
 o Cookie(String, String)
Constructs a Cookie with the given name and value, and with all other properties set to defaults.

Method Index

 o toString()
Constructs a Set-Cookie: string from the Cookie, according to the format prescribed by the version field.

Variables

 o version
 public int version
The version of the cookie. Used when constructing the string representation of the cookie. If 0, the original Netscape format is used, otherwise the format for the given version is used. Currently, only values of 0 (Netscape) and 1 (RFC 2109) are legal for the version. WARNING:Do not use version 1 cookies until this specification is widely supported by browsers. Defaults to 0 (Netscape).

 o name
 public String name
The name of the cookie. Required. Must not contain whitespace, semicolon(s), or equal sign(s).

 o value
 public String value
The value of the cookie. Required. Must not contain whitespace, semicolon(s), or equal sign(s).

 o comment
 public String comment
A comment which can be displayed to the client user when the cookie is received by the browser.

 o domain
 public String domain
The domain atrribute of the cookie. Optional. If null the domain defaults to the request-host.

 o maxAge
 public long maxAge
The maximum lifetime of the cookie in seconds. Optional. If less than zero (the default), the lifetime parameter is supressed when constructing the cookie. This causes the cookie to expire when the client/browser exits.

 o path
 public String path
The path attribute of the cookie. Optional. If null the path defaults to path of the request-URL that generates the Set-Cookie: response, up to but not including the right-most /.

 o secure
 public boolean secure
If true the cookie is sent by the browser only if it is using an encrypted (SSL) channel.

 o FROM_REQUEST
 public static final int FROM_REQUEST
A convenience value to indicate that the Cookie object should be constructed from a string of the format used in requests (with the Cookie: header).

 o FROM_RESPONSE
 public static final int FROM_RESPONSE
A convenience value to indicate that the Cookie object should be constructed from a string of the format used in responses (with the Set-Cookie: header).

Constructors

 o Cookie
 public Cookie(String name,
               String value)
Constructs a Cookie with the given name and value, and with all other properties set to defaults. Both the name and the value are required Cookie attributes.

Parameters:
name - The name of the cookie
value - The value of the cookie
 o Cookie
 public Cookie(String str,
               int type)
Constructs a Cookie object from a string representation of a cookie. Depending on the format parameter, the string is assumed to be from either a Cookie: header (sent by user-agents with their requests) or from a Set-Cookie: header (sent by the server). Note: This does not handle an entire Cookie: request header! You must break up the request header string into individual cookie elements according to the version of the cookie, then use the elements to construct separate cookies.

For version 0 (old Netscape format), each element is a simple NAME=VALUE pair (the pairs are separated by semicolons). Only the name and value properties of the resulting Cookie will have meaning, and the version property will be zero.

The structure for a version 1 (RFC 2109) cookie element is more complex. Refer to RFC 2109 for more information. In version 1, the user-agent may send the path and domain along with the NAME=VALUE pair. Thus, if the input string is in version 1 format, cookie's path and/or domain properties may be filled in.

Parameters:
str - The Cookie: request header element or the Set-Cookie: string.
type - The type of string (Cookie:/request or Set-Cookie:/response). Use Cookie.FROM_REQUEST or Cookie.FROM_RESPONSE respectively.

Methods

 o toString
 public String toString() throws ServletException
Constructs a Set-Cookie: string from the Cookie, according to the format prescribed by the version field. In the current version of this package, version 0 prescribes the original Netscape format, and version 1 prescribes the RFC 2109 format. Does not include the header label Set-Cookie:.

Throws: ServletException
Thrown if any of the cookie's properties are invalid. The detail message describes which field is invalid and why.
Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index