Top Description Fields Constructors Methods
org.springframework.web.util

public Class CookieGenerator

extends Object
Class Inheritance
Annotations
@Deprecated
Imports
jakarta.servlet.http.Cookie, .HttpServletResponse, org.apache.commons.logging.Log, .LogFactory, org.springframework.lang.Nullable, org.springframework.util.Assert

Deprecated

as of 6.0 in favor of org.springframework.http.ResponseCookie

Helper class for cookie generation, carrying cookie descriptor settings as bean properties and being able to add and remove cookie to/from a given response.

Can serve as base class for components that generate specific cookies.

Author
Juergen Hoeller
Since
1.1.4
See Also
addCookie, removeCookie

Field Summary

Modifier and TypeField and Description
private String
private boolean
private Integer
private String
private String
private boolean
protected final Log

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addCookie(HttpServletResponse
the HTTP response to add the cookie to
response
,
String
the value of the cookie to add
cookieValue
)

Add a cookie with the given value to the response, using the cookie descriptor settings of this generator.

protected Cookie

Returns:

the cookie
createCookie
(String
the value of the cookie to crate
cookieValue
)

Create a cookie with the given value, using the cookie descriptor settings of this generator (except for "cookieMaxAge").

public String
getCookieDomain()

Return the domain for cookies created by this generator, if any.

public Integer
getCookieMaxAge()

Return the maximum age for cookies created by this generator.

public String
getCookieName()

Return the given name for cookies created by this generator.

public String
getCookiePath()

Return the path for cookies created by this generator.

public boolean
isCookieHttpOnly()

Return whether the cookie is supposed to be marked with the "HttpOnly" attribute.

public boolean
isCookieSecure()

Return whether the cookie should only be sent using a secure protocol, such as HTTPS (SSL).

public void
removeCookie(HttpServletResponse
the HTTP response to remove the cookie from
response
)

Remove the cookie that this generator describes from the response.

public void
setCookieDomain(String cookieDomain)

Use the given domain for cookies created by this generator.

public void
setCookieHttpOnly(boolean cookieHttpOnly)

Set whether the cookie is supposed to be marked with the "HttpOnly" attribute.

public void
setCookieMaxAge(Integer cookieMaxAge)

Use the given maximum age (in seconds) for cookies created by this generator.

public void
setCookieName(String cookieName)

Use the given name for cookies created by this generator.

public void
setCookiePath(String cookiePath)

Use the given path for cookies created by this generator.

public void
setCookieSecure(boolean cookieSecure)

Set whether the cookie should only be sent using a secure protocol, such as HTTPS (SSL).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cookieDomainback to summary
private String cookieDomain
Annotations
@Nullable
cookieHttpOnlyback to summary
private boolean cookieHttpOnly
cookieMaxAgeback to summary
private Integer cookieMaxAge
Annotations
@Nullable
cookieNameback to summary
private String cookieName
Annotations
@Nullable
cookiePathback to summary
private String cookiePath
cookieSecureback to summary
private boolean cookieSecure
loggerback to summary
protected final Log logger

Constructor Detail

CookieGeneratorback to summary
public CookieGenerator()

Method Detail

addCookieback to summary
public void addCookie(HttpServletResponse response, String cookieValue)

Add a cookie with the given value to the response, using the cookie descriptor settings of this generator.

Delegates to createCookie for cookie creation.

Parameters
response:HttpServletResponse

the HTTP response to add the cookie to

cookieValue:String

the value of the cookie to add

See Also
setCookieName, setCookieDomain, setCookiePath, setCookieMaxAge
createCookieback to summary
protected Cookie createCookie(String cookieValue)

Create a cookie with the given value, using the cookie descriptor settings of this generator (except for "cookieMaxAge").

Parameters
cookieValue:String

the value of the cookie to crate

Returns:Cookie

the cookie

See Also
setCookieName, setCookieDomain, setCookiePath
getCookieDomainback to summary
public String getCookieDomain()

Return the domain for cookies created by this generator, if any.

Annotations
@Nullable
getCookieMaxAgeback to summary
public Integer getCookieMaxAge()

Return the maximum age for cookies created by this generator.

Annotations
@Nullable
getCookieNameback to summary
public String getCookieName()

Return the given name for cookies created by this generator.

Annotations
@Nullable
getCookiePathback to summary
public String getCookiePath()

Return the path for cookies created by this generator.

isCookieHttpOnlyback to summary
public boolean isCookieHttpOnly()

Return whether the cookie is supposed to be marked with the "HttpOnly" attribute.

isCookieSecureback to summary
public boolean isCookieSecure()

Return whether the cookie should only be sent using a secure protocol, such as HTTPS (SSL).

removeCookieback to summary
public void removeCookie(HttpServletResponse response)

Remove the cookie that this generator describes from the response. Will generate a cookie with empty value and max age 0.

Delegates to createCookie for cookie creation.

Parameters
response:HttpServletResponse

the HTTP response to remove the cookie from

See Also
setCookieName, setCookieDomain, setCookiePath
setCookieDomainback to summary
public void setCookieDomain(String cookieDomain)

Use the given domain for cookies created by this generator. The cookie is only visible to servers in this domain.

See Also
jakarta.servlet.http.Cookie#setDomain
setCookieHttpOnlyback to summary
public void setCookieHttpOnly(boolean cookieHttpOnly)

Set whether the cookie is supposed to be marked with the "HttpOnly" attribute.

Default is "false".

See Also
jakarta.servlet.http.Cookie#setHttpOnly
setCookieMaxAgeback to summary
public void setCookieMaxAge(Integer cookieMaxAge)

Use the given maximum age (in seconds) for cookies created by this generator. Useful special value: -1 ... not persistent, deleted when client shuts down.

Default is no specific maximum age at all, using the Servlet container's default.

See Also
jakarta.servlet.http.Cookie#setMaxAge
setCookieNameback to summary
public void setCookieName(String cookieName)

Use the given name for cookies created by this generator.

See Also
jakarta.servlet.http.Cookie#getName()
setCookiePathback to summary
public void setCookiePath(String cookiePath)

Use the given path for cookies created by this generator. The cookie is only visible to URLs in this path and below.

See Also
jakarta.servlet.http.Cookie#setPath
setCookieSecureback to summary
public void setCookieSecure(boolean cookieSecure)

Set whether the cookie should only be sent using a secure protocol, such as HTTPS (SSL). This is an indication to the receiving browser, not processed by the HTTP server itself.

Default is "false".

See Also
jakarta.servlet.http.Cookie#setSecure