JSTL标签库

1、Jsp Standard Tag Library (jsp标准标签库),用来替换传统页面中的<% %>

2、需要导包:standard.jar  jstl.jar

3、引入标签库 

  在jsp页面中导入:

    <%@taglib  prefix=""  uri="" %>

 <%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c”%>  prefix是前缀

4、c(core)核心标签库  介绍几个主要使用的标签

  if  注意:没有else

<c:if test="这里写EL表达式">
  如果EL表达式成立则执行这里
</c:if>

  choose  类似于switch

<c:choose>
  <c:when test="EL表达式">执行语句1</c:when>
  <c:when test="EL表达式">执行语句2</c:when>
  <c:otherwise>执行语句3</c:otherwise>
</c:choose>

  forEach

<!-- 循环打印数字 -->
<c:forEach begin="1" end="100" var="num">
      ${num }---    
</c:forEach>
<!-- 遍历数组或集合-->
<c:forEach items="${userList}" var="u" varStatus="aaa">
      ${u.id }---${u.name }---${u.age }===${aaa.index }===${aaa.count }<br/>
</c:forEach>
var就是每次循环取值的引用名称,varStatus是记数,index从0开始,count从1开始

5、fmt格式化标签库

  <%@ taglib uri=”http://java.sun.com/jsp/jstl/fmt” prefix=”fmt”%>

  <fmt:formatDate>标签:格式化时间和日期

例如:

<fmt:formatDate value="${current}"/>
通过type格式指定具体的格式形式。
<fmt:formatDate value="${d}"type="date"/>只格式成日期
<fmt:formatDate value="${d}"type="time"/>只格式成时间
<fmt:formatDate value="${d}"type="both"/>格式成日期+时间
通过pattern属性指定具体的格式要求
<fmt:formatDate value="${d}"pattern="yyyy-MM-dd"/>
原文地址:https://www.cnblogs.com/xfdhh/p/11409177.html