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

comment
- A comment which can be displayed to the client user when the cookie is received by the browser.
domain
- The domain atrribute of the cookie.
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).
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).
maxAge
- The maximum lifetime of the cookie in seconds.
name
- The name of the cookie.
path
- The path attribute of the cookie.
secure
- If true the cookie is sent by the browser only if it is using an encrypted (SSL) channel.
value
- The value of the cookie.
version
- The version of the cookie.

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

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

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).
name
public String name
-
The name of the cookie. Required. Must not contain whitespace, semicolon(s), or equal sign(s).
value
public String value
-
The value of the cookie. Required. Must not contain whitespace, semicolon(s), or equal sign(s).
comment
public String comment
-
A comment which can be displayed to the client user when the cookie is received by the browser.
domain
public String domain
-
The domain atrribute of the cookie. Optional. If null the domain defaults to the request-host.
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.
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 /.
secure
public boolean secure
-
If true the cookie is sent by the browser only if it is using an encrypted (SSL) channel.
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).
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).

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
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.

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