JSTL官方在线帮助文档:http://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/c/tld-summary.html
1、循环遍历List:(http://stackoverflow.com/questions/11954812/why-is-my-jstl-cif-test-should-be-true-returning-even-the-false-items)
<c:forEach var="value" items="${valueList}" varStatus="status">
<c:if test="${value.displayable}">
<c:if test="${status.index%2==0 }">
<li> <a href=""> title </a> <a href=""> link </a> </li>
</c:if>
<c:if test="${status.index%2!=0 }">
<li class="Odd"> <a href=""> title </a> <a href=""> link </a> </li>
</c:if>
</c:if>
</c:forEach>
<c:forEach items="${aMapWithData}" var="item" varStatus="status">
<td>
<c:out value="${status.count}."/>
<input type="text" name="${item.key}" value="${item.value}" />
</td>
</c:forEach>
3、c:when标签:(http://stackoverflow.com/questions/11898583/how-to-use-cwhen-condition-inside-value-attribute-of-input-tag)
<c:choose>
<c:when test="${texttest == 'Y'}">
Add
</c:when>
<c:otherwise>
Edit
</c:otherwise>
</c:choose>
<input id="textid" type="button" value="${texttest == 'Y' ? 'Add' : 'Edit'}">
4、lt 的用法:(http://stackoverflow.com/questions/11878188/what-does-this-lt-mean-in-jstl)
lt 即是less than 的缩写,相当于< ,它是EL操作符
<c:if test="${currentPage lt noOfPages}">
<td><a href="employee.do?page=${currentPage + 1}">Next</a></td>
</c:if>
5、<c:set>和<c:forEach>组合(http://stackoverflow.com/questions/11735059/how-to-update-value-in-cset-tag-using-el-inside-a-cforeach-tag)
In Java, it would look like this:
// before the loop:
int totalHours = 0;
for (Attendance attendance : list) {
totalHours = totalHours + attendance.getHours();
}
等效于
<c:set var="totalHours" value="${0}"/>
<c:forEach var="attendance" items="${list }" varStatus="rowCounter1">
...
<c:set var="totalHours" value="${totalHours + attendance.hours}"/>
</c:forEach>
6、如果值中含有html code 或者是url等值的时候,处理办法如下:(http://stackoverflow.com/questions/11701652/url-jstl-database)
<c:out value="${cursus.beschrijving}" escapeXml="false" />
或者这样写
${cursus.beschrijving}