类 CookieGenerator
- java.lang.Object
- org.springframework.web.util.CookieGenerator
public class CookieGenerator extends Object
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, such as CookieLocaleResolver and CookieThemeResolver.
- 从以下版本开始:
- 1.1.4
- 作者:
- Juergen Hoeller
- 另请参阅:
addCookie(javax.servlet.http.HttpServletResponse, java.lang.String)
,removeCookie(javax.servlet.http.HttpServletResponse)
,CookieLocaleResolver
,CookieThemeResolver
字段概要
字段 修饰符和类型 字段 说明 static String
DEFAULT_COOKIE_PATH
Default path that cookies will be visible to: "/", i.e. the entire server.protected Log
logger
构造器概要
构造器 构造器 说明 CookieGenerator()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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).
字段详细资料
DEFAULT_COOKIE_PATH
public static final String DEFAULT_COOKIE_PATH
Default path that cookies will be visible to: "/", i.e. the entire server.- 另请参阅:
- 常量字段值
构造器详细资料
CookieGenerator
public CookieGenerator()
方法详细资料
setCookieName
public void setCookieName(String cookieName)
Use the given name for cookies created by this generator.- 另请参阅:
Cookie.getName()
getCookieName
public String getCookieName()
Return the given name for cookies created by this generator.
setCookieDomain
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.
getCookieDomain
public String getCookieDomain()
Return the domain for cookies created by this generator, if any.
setCookiePath
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.
getCookiePath
public String getCookiePath()
Return the path for cookies created by this generator.
setCookieMaxAge
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.
getCookieMaxAge
public Integer getCookieMaxAge()
Return the maximum age for cookies created by this generator.
setCookieSecure
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".
isCookieSecure
public boolean isCookieSecure()
Return whether the cookie should only be sent using a secure protocol, such as HTTPS (SSL).
setCookieHttpOnly
public void setCookieHttpOnly(boolean cookieHttpOnly)
Set whether the cookie is supposed to be marked with the "HttpOnly" attribute.Default is "false".
isCookieHttpOnly
public boolean isCookieHttpOnly()
Return whether the cookie is supposed to be marked with the "HttpOnly" attribute.
addCookie
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(java.lang.String)
for cookie creation.- 参数:
response
- the HTTP response to add the cookie tocookieValue
- the value of the cookie to add- 另请参阅:
setCookieName(java.lang.String)
,setCookieDomain(java.lang.String)
,setCookiePath(java.lang.String)
,setCookieMaxAge(java.lang.Integer)
removeCookie
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(java.lang.String)
for cookie creation.- 参数:
response
- the HTTP response to remove the cookie from- 另请参阅:
setCookieName(java.lang.String)
,setCookieDomain(java.lang.String)
,setCookiePath(java.lang.String)
createCookie
protected Cookie createCookie(String cookieValue)
Create a cookie with the given value, using the cookie descriptor settings of this generator (except for "cookieMaxAge").- 参数:
cookieValue
- the value of the cookie to crate- 返回:
- the cookie
- 另请参阅:
setCookieName(java.lang.String)
,setCookieDomain(java.lang.String)
,setCookiePath(java.lang.String)