Tuesday, September 27, 2011

JSP and JSTL samples

Adding JSTL to your page. Formatting will vary based on version. Visit this excellent FAQ on JSTL on JavaRanch.

Perform an IF check.
<c:if test="${param.job == 'Other'}">
// conditional HTML here
</c:if>


For IF/ELSE, use Choose When/Otherwise
<c:choose>
<c:when test="${param.home != '1'}">
<input type="hidden" name="Home" value="0">
</c:when>
<c:otherwise>
<input type="hidden" name="Home" value="1">
</c:otherwise>
</c:choose>


Add the current date to your page with JSTL.

<fmt:formatDate type="date" dateStyle="long" value="<%=new java.util.Date()%>" />

No comments:

Post a Comment