Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

For more information on Velocity itself, please visit the Velocity website.

Info

Velocity is similar to FreeMarker, as both are template languages that can be used outside of a Servlet container. The framework uses FreeMarker internally since it has better error reporting. Developers may also like that FreeMarker supports JSP taglibs. However, both are good alternatives to JSP.

...

Getting started with Velocity is as simple as ensuring all the dependencies are included in your project's classpath. Other than that, struts-default.xml already configures the Velocity Result.

Code Block
xml
xml
titlestruts.xml
<action name="test" class="com.acme.TestAction">
    <result name="success" type="velocity">test-success.vm</result>
</action>

...

Since the action context is resolved after the value stack, you can reference the variable without the typical preceding marker (#) that has to be used with the JSP s:property tag. Omitting the marker can be convenient, but it can also trip you up, if used carelessly.

Code Block
xml
xml
#s-url#surl "id=url" "value=http://www.yahoo.com"
Click <a href="${url}">here</a>!

...

You can configure Velocity by placing configuration items in velocity.properties.

Next: Velocity Tags