类 CookieTool
java.lang.Object
org.apache.velocity.tools.view.CookieTool
- 直接已知子类:
CookieTool
View tool for convenient cookie access and creation.
Template example(s): $cookie.foo $cookie.add("bar",'woogie') tools.xml configuration: <tools> <toolbox scope="request"> <tool class="org.apache.velocity.tools.view.CookieTool"/> </toolbox> </tools>
This class is only designed for use as a request-scope tool.
- 从以下版本开始:
- VelocityTools 2.0
- 版本:
- $Id: CookieTool.java 740389 2009-02-03 19:38:36Z nbubna $
- 作者:
- Dmitri Colebatch, Nathan Bubna
-
嵌套类概要
嵌套类修饰符和类型类说明static class
ExtendsCookie
to add some fluid API sugar and a toString() method that renders the Cookie's value instead of the usual Object.toString() shenanigans. -
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明add
(Cookie c) Adds the specified Cookie to the HttpServletResponse.Adds a new Cookie with the specified name and value to the HttpServletResponse.Convenience method to add a new Cookie to the response and set an expiry time for it.Cookie
Creates a new Cookie with the specified name and value.Cookie
Convenience method to create a new Cookie and set an expiry time for it.Retrieves the specified cookie and sets the Max-Age to 0 to tell the browser to delete the cookie.Cookie
Returns the Cookie with the specified name, if it exists.List<Cookie>
getAll()
Expose array of Cookies for this request to the template.void
setLog
(org.apache.velocity.runtime.log.Log log) Sets theLog
used for logging messages when Cookie creation fails due to an invalid name.void
setRequest
(HttpServletRequest request) Sets the currentHttpServletRequest
.void
setResponse
(HttpServletResponse response) Sets the currentHttpServletResponse
.toString()
-
字段详细资料
-
request
protected HttpServletRequest request -
response
protected HttpServletResponse response -
log
protected org.apache.velocity.runtime.log.Log log -
jar
-
-
构造器详细资料
-
CookieTool
public CookieTool()
-
-
方法详细资料
-
setRequest
public void setRequest(HttpServletRequest request) Sets the currentHttpServletRequest
. This is required for this tool to operate and will throw a NullPointerException if this is not set or is set tonull
. -
setResponse
public void setResponse(HttpServletResponse response) Sets the currentHttpServletResponse
. This is required for this tool to operate and will throw a NullPointerException if this is not set or is set tonull
. -
setLog
public void setLog(org.apache.velocity.runtime.log.Log log) Sets theLog
used for logging messages when Cookie creation fails due to an invalid name. -
getAll
Expose array of Cookies for this request to the template.This is equivalent to
$request.cookies
.- 返回:
- list of Cookie objects for this request
-
get
Returns the Cookie with the specified name, if it exists.So, if you had a cookie named 'foo', you'd get it's value by
$cookies.foo.value
or it's max age by$cookies.foo.maxAge
-
add
Adds the specified Cookie to the HttpServletResponse. This does *not* add the Cookie to the current request.- 参数:
c
- is for cookie (that's good enough for me)- 返回:
- an empty String to prevent the reference from rendering unless the cookie passed in is null, then it returns null
- 从以下版本开始:
- VelocityTools 2.0
-
add
Adds a new Cookie with the specified name and value to the HttpServletResponse. This does *not* add a Cookie to the current request.- 参数:
name
- the name to give this cookievalue
- the value to be set for this cookie- 返回:
- an empty String to prevent the reference from rendering
-
add
Convenience method to add a new Cookie to the response and set an expiry time for it.- 参数:
name
- the name to give this cookievalue
- the value to be set for this cookiemaxAge
- the expiry to be set for this cookie- 返回:
- an empty String to prevent the reference from rendering
-
create
Creates a new Cookie with the specified name and value. This does *not* add the Cookie to the response, so the created Cookie will not be set unless you do$cookies.add($myCookie)
.- 参数:
name
- the name to give this cookievalue
- the value to be set for this cookie- 返回:
- The new SugarCookie object.
- 从以下版本开始:
- VelocityTools 1.3
-
create
Convenience method to create a new Cookie and set an expiry time for it.- 参数:
name
- the name to give this cookievalue
- the value to be set for this cookiemaxAge
- the expiry to be set for this cookie- 返回:
- The new SugarCookie object.
- 从以下版本开始:
- VelocityTools 1.3
-
delete
Retrieves the specified cookie and sets the Max-Age to 0 to tell the browser to delete the cookie. Then this returns an empty string to make this render silently. If no such cookie exists, then it returns null to show the error.- 参数:
name
- the name of the cookie to be eaten- 返回:
- empty string, or null if no such cookie exists
- 另请参阅:
-
Cookie#setMaxAge
add(Cookie)
get(String)
-
toString
-