Class Cookies

public class Cookies
extends Object
Provides access to browser cookies stored on the client. Because of browser restrictions, you will only be able to access cookies associated with the current page's domain.

Methods

getCookie(String)Gets the cookie associated with the given name.
getCookieNames()Gets the names of all cookies in this page's domain.
removeCookie(String)Removes the cookie associated with the given name.
setCookie(String, String)Sets a cookie.
setCookie(String, String, Date)Sets a cookie.
setCookie(String, String, Date, String, String, boolean)Sets a cookie.

Method Detail

getCookie

public static String getCookie(String name)
Gets the cookie associated with the given name.

Parameters

name
the name of the cookie to be retrieved

Return Value

the cookie's value, or null if the cookie doesn't exist

getCookieNames

public static Collection getCookieNames()
Gets the names of all cookies in this page's domain.

Return Value

the names of all cookies

removeCookie

public static void removeCookie(String name)
Removes the cookie associated with the given name.

Parameters

name
the name of the cookie to be removed

setCookie

public static void setCookie(String name, String value)
Sets a cookie. The cookie will expire when the current browser session is ended.

Parameters

name
the cookie's name
value
the cookie's value

setCookie

public static void setCookie(String name, String value, Date expires)
Sets a cookie.

Parameters

name
the cookie's name
value
the cookie's value
expires
when the cookie expires

setCookie

public static void setCookie(String name, String value, Date expires, String domain, String path, boolean secure)
Sets a cookie.

Parameters

name
the cookie's name
value
the cookie's value
expires
when the cookie expires
domain
the domain to be associated with this cookie
path
the path to be associated with this cookie
secure
true to make this a secure cookie