Creating, accessing and deleting Cookies using Velocity CookieTool

Description

Velocity provides a viewtool to create, access and delete cookies. The tool is called: CookieTool and can be used on a widget by calling: org.apache.velocity.tools.view.tools.CookieTool@4f0cfa32.

You can find more information about this tool at:
http://www.jajakarta.org/velocity/tools/velocity-tools-1.1/docs/view/CookieTool.html

Code

##Get cookies
#if($cookietool.get("cookie1"))
cookie1: $cookietool.get("cookie1").value
#end
#if($cookietool.get("cookie2"))
cookie2: $cookietool.get("cookie2").value
#end
#if($cookietool.get("cookie3"))
cookie3: $cookietool.get("cookie3").value
#end

#if($request.getParameter("delete"))
##Delete cookies
$cookietool.add("cookie1","",0)
$cookietool.add("cookie2","",0)
$cookietool.add("cookie3","",0)
#end

#if($request.getParameter("add"))
##Add four cookies
$cookietool.add("cookie1",'cookie1value')
$cookietool.add("cookie2",'cookie2value')
$cookietool.add("cookie3",'cookie3value')
#end

##Print all cookie names
#set($cookies = $cookietool.getAll())
#foreach($c in $cookies)
  $c.getName()
#end