The Jakarta Project < Tools - View >

Velocity Tools

VelocityView

VelocityView Tools

Other Subprojects

CookieTool Reference Documentation
       

View tool for convenient cookie access and creation.

Class
 org.apache.velocity.tools.view.tools.CookieTool
Name
 $cookie (this is the recommended name of the tool in the Velocity context)
Toolbox Configuration Example
 
<tool>
  <key>cookie</key>
  <scope>request</scope>
  <class>org.apache.velocity.tools.view.tools.CookieTool</class>
</tool>
Author(s)
 Dmitri Colebatch
Nathan Bubna
Method Overview
getAll() Expose array of Cookie objects for this request to the template.
get() Returns the Cookie with the specified name, if it exists.
add() Adds a new Cookie with the specified name and value to the HttpServletResponse.
getAll()
       

Expose array of Cookie objects for this request to the template.

Cookie[] getAll()

Returns
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)

Parameters
name
The name of the cookie to fetch.
Returns
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)

Parameters
name
The name to give this cookie.
value
The value to be set for this cookie.
maxAge
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")


Copyright © 1999-2003, Apache Software Foundation