The VelocityStruts sub-project integrates Velocity with the
web application framework and enables the use of Velocity templates
interchangeably with JSP pages for the view layer.
web application frameworks
offer built-in support for Velocity templates. This project
provides the minimal glue necessary to give Struts developers
an alternative to JSP.
Diagram 1. Comparison of JSP and Velocity for
the view layer in a Struts application.
As we follow the typical Struts process flow in Diagram 1,
notice how there is relatively little change except for the addition
of Velocity. The velocity-struts.jar leverages a standalone Velocity
servlet to process template files (specifically, the jar file is
velocity-tools-x.x.jar) and uses some drop-in tools to provide
transparent access to Struts specific objects (ex. message resources,
form beans, errors, links). The action mapping file will simply contain
ActionForwards that send control to a Velocity-based View layer instead
of sending to a JSP.
Also notable is that Velocity and JSP are not
mutually exclusive. Both technologies can be used in the same
application without any problems. This allows developers the option
of trying Velocity without heavy modification to existing applications.
We're convinced that once you give Velocity a try, you'll really like it.