<title>Velocity-Style Syntax</title>

The Apache <a href="http://jakarta.apache.org/velocity">Velocity</a>
project introduces an alternative syntax to the familiar JSP
expressions and scriptlets.  Resin's extension allows the use
of Velocity-style syntax in JSP files.  Resin's extension does not
implement Velocity's language or its data structures.  It's simply an
alternative JSP syntax.  The Velocity-style syntax was introduces
in Resin 2.0.3.

<p/>The syntax is based on expressions like <var/$foo/> and <var/${foo}/>
and scriptlets with <var/#{...}#/>.  Because the
alternative syntax avoids the brackets which fill JSP pages, it can make
pages more readable and therefore more maintainable.

<example title='JSP style'>
&lt;%
int count;
%>

&lt;h3>A sample &lt;%= count %>&lt;/h3>

&lt;% if ("foo".equals(request.getParameter("a"))) { %>
  &lt;h3>Foo!&lt;/h3>
&lt;% } else { %>
  &lt;h3>Bar!&lt;/h3>
&lt;% } %>
</example>

<p/>The same JSP file could be written in Velocity-style as follows.  The
jsp:directive is required because JSP pages use strict JSP syntax
by default.

<example title='Velocity style'>
&lt;jsp:directive.page velocity='true'/>
#{
int count;
}#

&lt;h3>A sample $count&lt;/h3>

#if ("foo".equals(request.getParameter("a")))
  &lt;h3>Foo!&lt;/h3>
#else
  &lt;h3>Bar!&lt;/h3>
#end
</example>

<p/>The choice between the two is a matter of preferences.  An advantage
of the velocity style is that expressions and scriptlets avoid using
brackets.  In large pages, sorting out the HTML or XML from the JSP syntax
can become confusing.

<subsection title='expressions'>

Expressions start with the dollar sign, '$', like many
scripting languages.  A simple identifier can follow the '$',
like '$count'.  More complicated expressions need to use parentheses for grouping: '${count + 15}'.

<p/>The '${...}' syntax is equivalent to '&lt;%= ... %>'.  (This is a bit
different from Velocity in its handling of null values.)

</subsection>

<subsection title='scriptlets'>

Scriptlets use the '#{ ... }#' syntax.  This is entirely equivalent to
'&lt;% ... %>'.  (Note, Velocity does not have this syntax because it
creates its own language instead of escaping to Java.)

<example>
#{
String key = request.getParameter("key");
if (key.equals("")) {
  response.sendError(500, "Bad key");
  return;
}
}#
...
</example>

</subsection>

<subsection title='if statements'>

The velocity-style syntax directly supports if statements.  The syntax is

<def>
#if (expr)
  ...
#elseif (expr)
  ...
#else
  ...
#end
</def>

The expressions can be any Java expression.

</subsection>
