public class HttpCookie extends Object
Cookies are a general mechanism which server side connections (such as CGI scripts) can use to both store and retrieve information on the client side of the connection. The addition of a simple, persistent, client-side state significantly extends the capabilities of Web-based client/server applications.
A server, when returning an HTTP object to a client, may also send a piece of state information which the client will store. Included in that state object is a description of the range of URLs for which that state is valid. Any future HTTP requests made by the client which fall in that range will include a transmittal of the current value of the state object from the client back to the server. The state object is called a cookie, for no compelling reason.
This simple mechanism provides a powerful new tool which enables a host of new types of applications to be written for web-based environments. Shopping applications can now store information about the currently selected items, for fee services can send back registration information and free the client from retyping a user-id on next connection, sites can store per-user preferences on the client, and have the client supply those preferences every time that site is connected to.
For a complete specification of the cookies, see RFC2109 or see the old (and different) HTTP/1.0 Netscape specification.
Note: Do not specify a name of the cookie starting with "$", it is reserved!
Modifier and Type | Field and Description |
---|---|
String |
comment
The comment of the cookie.
|
String |
domain
The domain of the cookie or null for none.
|
boolean |
isSecure
Flag indicating the cookie is only transferred when a secure connection exists.
|
boolean |
isVersion1
The version of this cookie: true when using RFC2109 standard, false when using old
Netscape version.
|
int |
maxAge
Timeout in seconds of the cookie (-1 if none or when validity date is specified).
|
String |
name
The name of the cookie.
|
String |
path
The path to the cookie or null if not specified.
|
Date |
validity
The valid until timestamp or null when not specified (for Netscape HTTP/1.0 cookie).
|
String |
value
The value of the cookie.
|
Constructor and Description |
---|
HttpCookie(String name,
String value)
Creates a cookie to be transfered to the client in the next HTTP reply.
|
HttpCookie(String name,
String value,
boolean isVersion1)
Creates a cookie to be transfered to the client in the next HTTP reply.
|
HttpCookie(String name,
String value,
String path,
boolean isVersion1)
Creates a cookie to be transfered to the client in the next HTTP reply.
|
HttpCookie(String name,
String value,
String path,
String domain,
boolean isVersion1)
Creates a cookie to be transfered to the client in the next HTTP reply.
|
HttpCookie(String name,
String value,
String path,
String domain,
Date validity)
Creates a cookie to be transfered to the client in the next HTTP reply.
|
HttpCookie(String name,
String value,
String comment,
String path,
String domain,
Date validity,
int maxAge,
boolean isSecure,
boolean isVersion1)
Creates a cookie to be transfered to the client in the next HTTP reply.
|
Modifier and Type | Method and Description |
---|---|
String |
getHeaderFieldData()
Gets the string representation of this cookie for the server HTTP header field reply using
"Set-Cookie: NAME=VALUE [; expires=DATE] [; path=PATH] [; domain=DOMAIN] [; secure] \r\n".
|
public final String name
public final String value
public final String comment
public final String path
public final String domain
public final Date validity
public final int maxAge
public final boolean isVersion1
public final boolean isSecure
public HttpCookie(String name, String value)
This will create a cookie in the version 1 format.
public HttpCookie(String name, String value, boolean isVersion1)
This will create a cookie in the version 1 format depending of the
isVersion1
parameter.
public HttpCookie(String name, String value, String path, boolean isVersion1)
This will create a cookie in the version 1 format depending of the
isVersion1
parameter.
public HttpCookie(String name, String value, String path, String domain, boolean isVersion1)
This will create a cookie in the version 1 format depending of the
isVersion1
parameter.
public HttpCookie(String name, String value, String path, String domain, Date validity)
This will create a non-version 1 cookie in the old Netscape format.
public HttpCookie(String name, String value, String comment, String path, String domain, Date validity, int maxAge, boolean isSecure, boolean isVersion1)
To use version 1 of the cookie, set validity=null
and optionally
specify maxAge
to -1 or >=0.
public String getHeaderFieldData()
The NAME and the VALUE are escaped using "%xx" URL style.
Phantom® and NetPhantom® are registered trademarks of Mindus SARL.
© © Mindus SARL, 2024. All rights reserved.