It’s very easy to concatenate strings and combine expressions in JSTL.
Here is an example:
<c:set var="query" value="${nextAction}?item=${param.item}"/>
Anything not enclosed in ${…} is treated like a literal, and expressions inside the curly brackets are evaluated. So if ${nextAction} has the value of "viewCart.do" and ${param.item} has the value of "1234", the value of the query variable will be as follows:
viewCart.do?item=1234
Also, you can concatenate a variable to itself as follows:
<c:set var=’myVar’ value=’myValue’>
<c:set var=’myVar’ value= ‘${myVar} and some other value’ />
This can be useful if you deal with iterations. An example:
<c:forTokens var="token" delims=":" items="a:b:c:d:e">
<c:set var=’myVar‘ value=’${myVar} ${token} and’ />
</c:forTokens>
<c:out value=’${myVar}’/> outputs ‘a and b and c and d and e and‘.
You can skip the last iteration using the varStatus variable:
<c:forTokens var="token" delims=":" items="a:b:c:d:e" varStatus=’vs‘>
<c:set var=’where’ value=’${where} workorder_id = ${token}’ />
<c:if test = "${!vs.last}">
<c:set var=’myVar’ value=’${myVar} ${token} and’ />
</c:if>
</c:forTokens>
Visit http://www.ekcsoft.com/coding/java/jstl_parameters to learn how to display and sort all request parameters with JSTL.
