- http://www.visards.co.jp/java/jstl/jstl03.html
※ JSTLのtaglibのURIは変更になっている。→http://www.bugbearr.jp/?Java%2FJSTL
- 個別のJSPでJSTLのtaglib宣言を省略する
http://www.atmarkit.co.jp/fjava/javatips/119jspservlet39.html
- c:out と fn:escapeXml の使い分け
http://www.bugbearr.jp/?Java%2FJSTL#mfac3622
使用例
tablib宣言
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
ifとforEach
<c:if test="${pageCount > 0}">
<c:forEach var="p" begin="0" end="${pageCount-1}">
<c:choose>
<c:when test="${p != page}">
<a href = "?page=${p}">${p + 1}</a>
</c:when>
<c:otherwise>
${p+1}
</c:otherwise>
</c:choose>
</c:forEach>
</c:if>
<table>
<tr>
<th>ID</th>
<th>氏名</th>
<th>備考</th>
</tr>
<c:forEach var="user" items="${userList}">
<tr>
<td>${fn:escapeXml(user.id)}</td>
<td>${fn:escapeXml(user.name)}</td>
<td><pre>${fn:escapeXml(user.remark)}</pre></td>
</tr>
</c:forEach>
</table>
empty
<c:if test="${! empty errorList}">
<%-- errorList==nullの場合だけでなく errorList.size()==0の場合も
empty errorList == trueとなるようだ。たまたま?仕様?要確認。 --%>
<ul>
<c:forEach var="error" items="${errorList}">
<li>${fn:escapeXml(error)}</li>
</c:forEach>
</ul>
</c:if>
リストの要素数の取得
fn:length を使うらしい。