需要在jsp中加入以下标签库和函数库
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>? //必须
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> //需要格式化一些参数时使用,非必须
?
?
1.遍历list<对象>
<c:forEach items="${list}" var="list" varStatus="status"> ???
???? ? ? ? ? ? ${list.name} ?????
</c:forEach>
?
2.遍历list<String>
<c:forEach items="${optList}" var="optList" varStatus="status"> ???
???? ? ? ? ? ? ${optList} ?????
</c:forEach>
?
3.遍历list<Map<String,String>>
<c:forEach var="name" items="${a}">
?? <c:forEach var="entry" items="${name}">
????? <c:out value="${entry.key}"/>
????? <c:out value="${entry.value}"/>
??? </c:forEach>
</c:forEach>
?
4.遍历map
<c:forEach items="${map}" var="mymap" >
?? <c:out value="${mymap.key}" />
?? <c:out value="${mymap.value}" />
</c:forEach>
?
5.if使用
首先在jsp中加入
<c:if test="${salary > 2000}"> <p>My salary is: <c:out value="${salary}"/><p> </c:if>
6.choose标签<c:choose>
?? <c:when test="${param<=2}">?
??????????? 1
?? </c:when>
?? <c:when test="${param>=2}">?
??????????? 2
?? </c:when>
?? <c:otherwise>
?????????? ${param}
?? </c:otherwise>
</c:choose>
原文:http://lafecat.iteye.com/blog/2229235