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@79710369.

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

Code

${esc.h}${esc.h}Get cookies
${esc.h}if(${esc.d}cookietool.get("cookie1"))
cookie1: ${esc.d}cookietool.get("cookie1").value
${esc.h}end
${esc.h}if(${esc.d}cookietool.get("cookie2"))
cookie2: ${esc.d}cookietool.get("cookie2").value
${esc.h}end
${esc.h}if(${esc.d}cookietool.get("cookie3"))
cookie3: ${esc.d}cookietool.get("cookie3").value
${esc.h}end

${esc.h}if(${esc.d}request.getParameter("delete"))
${esc.h}${esc.h}Delete cookies
${esc.d}cookietool.add("cookie1","",0)
${esc.d}cookietool.add("cookie2","",0)
${esc.d}cookietool.add("cookie3","",0)
${esc.h}end

${esc.h}if(${esc.d}request.getParameter("add"))
${esc.h}${esc.h}Add four cookies
${esc.d}cookietool.add("cookie1",'cookie1value')
${esc.d}cookietool.add("cookie2",'cookie2value')
${esc.d}cookietool.add("cookie3",'cookie3value')
${esc.h}end

${esc.h}${esc.h}Print all cookie names
${esc.h}set(${esc.d}cookies = ${esc.d}cookietool.getAll())
${esc.h}foreach(${esc.d}c in ${esc.d}cookies)
  ${esc.d}c.getName()
${esc.h}end