JSTL 使用
- 導(dǎo)包1.2 jar
- 解壓 \jstl-1.2\META-INF\c.tld
- uri
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
前導(dǎo)設(shè)置:prefix="c" 值隨意魔策,但是經(jīng)常寫成c
具體使用:
1.循環(huán)遍歷普通數(shù)據(jù)(for)<br>
<ul>
<c:forEach var="i" begin="1" end="5" step="1">
<li>${i } </li>
</c:forEach>
</ul>
<hr>
2.循環(huán)遍歷普通數(shù)據(jù)(fore)<br>
<ul>
<c:forEach var="i" items="${list }" >
<li>${i } </li>
</c:forEach>
</ul>
<hr>
3.循環(huán)遍歷對象數(shù)據(jù)(fore)<br>
<ul>
<c:forEach var="i" items="${ulist }" >
<li>
${i.name }
${i.age }
${i.sex }
</li>
</c:forEach>
</ul>
4.循環(huán)遍歷對象數(shù)據(jù)(fore)if<br>
<ul>
<c:forEach var="i" items="${ulist }" >
<li>
${i.name }
${i.age }
<c:choose>
<c:when test="${i.sex == 1 }">
男
</c:when>
<c:when test="${i.sex == 2 }">
女
</c:when>
<c:otherwise>
保密
</c:otherwise>
</c:choose>
</li>
</c:forEach>
</ul>
注意:<c:choose>千萬別忘