public class CookieGenerator extends Object
Can serve as base class for components that generate specific cookies, such as CookieLocaleResolver and CookieThemeResolver.
addCookie(javax.servlet.http.HttpServletResponse, java.lang.String)
,
removeCookie(javax.servlet.http.HttpServletResponse)
,
CookieLocaleResolver
,
CookieThemeResolver
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_COOKIE_MAX_AGE
Deprecated.
in favor of setting no max age value at all in such a case
|
static String |
DEFAULT_COOKIE_PATH
Default path that cookies will be visible to: "/", i.e.
|
protected Log |
logger |
Constructor and Description |
---|
CookieGenerator() |
Modifier and Type | Method and Description |
---|---|
void |
addCookie(HttpServletResponse response,
String cookieValue)
Add a cookie with the given value to the response,
using the cookie descriptor settings of this generator.
|
protected Cookie |
createCookie(String cookieValue)
Create a cookie with the given value, using the cookie descriptor
settings of this generator (except for "cookieMaxAge").
|
String |
getCookieDomain()
Return the domain for cookies created by this generator, if any.
|
Integer |
getCookieMaxAge()
Return the maximum age for cookies created by this generator.
|
String |
getCookieName()
Return the given name for cookies created by this generator.
|
String |
getCookiePath()
Return the path for cookies created by this generator.
|
boolean |
isCookieHttpOnly()
Return whether the cookie is supposed to be marked with the "HttpOnly" attribute.
|
boolean |
isCookieSecure()
Return whether the cookie should only be sent using a secure protocol,
such as HTTPS (SSL).
|
void |
removeCookie(HttpServletResponse response)
Remove the cookie that this generator describes from the response.
|
void |
setCookieDomain(String cookieDomain)
Use the given domain for cookies created by this generator.
|
void |
setCookieHttpOnly(boolean cookieHttpOnly)
Set whether the cookie is supposed to be marked with the "HttpOnly" attribute.
|
void |
setCookieMaxAge(Integer cookieMaxAge)
Use the given maximum age (in seconds) for cookies created by this generator.
|
void |
setCookieName(String cookieName)
Use the given name for cookies created by this generator.
|
void |
setCookiePath(String cookiePath)
Use the given path for cookies created by this generator.
|
void |
setCookieSecure(boolean cookieSecure)
Set whether the cookie should only be sent using a secure protocol,
such as HTTPS (SSL).
|
public static final String DEFAULT_COOKIE_PATH
@Deprecated public static final int DEFAULT_COOKIE_MAX_AGE
protected final Log logger
public void setCookieName(String cookieName)
Cookie.getName()
public String getCookieName()
public void setCookieDomain(String cookieDomain)
Cookie.setDomain(java.lang.String)
public String getCookieDomain()
public void setCookiePath(String cookiePath)
Cookie.setPath(java.lang.String)
public String getCookiePath()
public void setCookieMaxAge(Integer cookieMaxAge)
Cookie.setMaxAge(int)
public Integer getCookieMaxAge()
public void setCookieSecure(boolean cookieSecure)
Cookie.setSecure(boolean)
public boolean isCookieSecure()
public void setCookieHttpOnly(boolean cookieHttpOnly)
Note that this feature is only available on Servlet 3.0 and higher.
Cookie.setHttpOnly(boolean)
public boolean isCookieHttpOnly()
public void addCookie(HttpServletResponse response, String cookieValue)
Delegates to createCookie(java.lang.String)
for cookie creation.
response
- the HTTP response to add the cookie tocookieValue
- the value of the cookie to addsetCookieName(java.lang.String)
,
setCookieDomain(java.lang.String)
,
setCookiePath(java.lang.String)
,
setCookieMaxAge(java.lang.Integer)
public void removeCookie(HttpServletResponse response)
Delegates to createCookie(java.lang.String)
for cookie creation.
response
- the HTTP response to remove the cookie fromsetCookieName(java.lang.String)
,
setCookieDomain(java.lang.String)
,
setCookiePath(java.lang.String)
protected Cookie createCookie(String cookieValue)
cookieValue
- the value of the cookie to cratesetCookieName(java.lang.String)
,
setCookieDomain(java.lang.String)
,
setCookiePath(java.lang.String)