November 06, 2009

JSTL Example

« Java CLI | Main | Java Monitoring Project »

The JavaServer Pages Standard Tag Library (JSTL) provides a better separation between HTML code and dynamic content. It encapsulates iterative or conditional processing, XML transformation, accessing datasources and localization.

Useful JSTL and Non-JSTL Tag-Libs are:

  • Conditional or iterative processing: <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  • XML tranformation: <%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>
  • e.g. date format or localization: <%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
Usage example (Example.jsp). List orders from an session attribute:
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<body>
 <ul>
  <c:forEach var="orderItem" items="${sessionScope.ORDERS}">
   <li>${orderItem.name}</li>
   <li>${orderItem.amount}</li>
   <li>${orderItem.singlePrice}</li>
  </c:forEach>
</body>
</html>
Regards
Rafael

Technorati Tags:

Posted by rafael.sobek at 8:34 AM in Java

 

[Trackback URL for this entry]

Your comment:

(not displayed)
 
 
 

Live Comment Preview:

 
« November »
SunMonTueWedThuFriSat
1234567
891011121314
15161718192021
22232425262728
2930