Prefer JSTL tags

JSTL is a standard set of tags used for implementing common tasks in Java Server Pages. It is probably best to prefer the JSTL over other tag libraries, if possible, since the average web programmer can be expected to be familiar with it.

To give an example of typical JSTL syntax, here are some JSP snippets which uses the core, format, and function parts of JSTL :

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
...

<c:forEach var="restaurant" items="${itemsForListing}" varStatus="index">
 <tr class="row_highlight">
  <td title="Line Number">${index.count}</td>
  <td>${restaurant.name}</td>
  <td align="center">${restaurant.location}</td>
  <td>${restaurant.price}</td>
  <td align="center">${restaurant.comment}</td>
 </tr>
</c:forEach>
...

System Properties (${fn:length(systemProperties)})
<c:forEach var="entry" items="${systemProperties}">
 <b>${entry.key}</b> = ${entry.value}
</c:forEach>


<jsp:useBean id="now" class="java.util.Date" />
Copyright <fmt:formatDate value="${now}" pattern="yyyy" /> 



See Also :
Emit flexible URLs
Always maintain HttpSessions
Would you use this technique?
Yes   No   Undecided   
© 2010 Hirondelle Systems | Source Code | Contact | License | Quotes | RSS
Individual code snippets can be used under this BSD license - Last updated on June 5, 2010.
Over 150,000 unique IPs last month - Built with WEB4J.
- In Memoriam : Bill Dirani -