JSTL foreach及if when标签使用

需要在jsp中加入以下标签库和函数库

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>  //必须
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> //需要格式化一些参数时使用,非必须

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>//对数据进行处理时,需要用到的函数,非必须

 

 

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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值