CookieTool Reference Documentation

View tool for convenient cookie access and creation.

@@@version@@@, @@@date@@@org.apache.velocity.tools.view.tools.CookieTool$cookieDmitri ColebatchNathan Bubna<tool> <key>cookie</key> <scope>request</scope> <class>org.apache.velocity.tools.view.tools.CookieTool</class> </tool>

getAll()

Expose array of Cookie objects for this request to the template. Cookie[] getAll() array of Cookie objects for this request.

This method exposes the array of Cookie objects for this request. It is equivalent to $request.cookies.

#set($cookies = $cookie.getAll()) #foreach($c in $cookies) $c.getName() #end

Given that there are two cookies with the names 'foo' and 'bar' in the array this would produce:

foo bar

get()

Returns the Cookie with the specified name, if it exists. Cookie get(String name) The name of the cookie to fetch. A Cookie with the specified name or null if none exists.

Returns the Cookie with the specified name, if it exists.

$cookie.foo.value

Given that the cookie 'foo' contains the value 'bar' this would produce:

bar

add()

Adds a new Cookie with the specified name and value to the HttpServletResponse. void add(String name, String value) void add(String name, String value, int maxAge) The name to give this cookie. The value to be set for this cookie. The expiry to be set for this cookie.

Adds a new Cookie with the specified name and value to the HttpServletResponse. This does *not* add a Cookie to the current request.

$cookie.add("bar","woogie")