JSTL(JSP 标准标签库)
Core
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
属性设置
<c:set> 设置属性
<c:remove> 移除设置的属性
过程控制
<c:if test="..."> 条件标签只有在test 属性的值为true 是才会执行标签体
例:
<c:if test="${!(empty user.age)}">
<h1>hello</h1>
</c:if>
<c:choose>choose 和when 是组合在一起使用的,有点类似于swith case 的语法。
<c:when test="...">when 也是条件判断标签,test 属性的值为true 是才会执行标签体。
例:
<c:choose>
<c:when test="${param.age<18}">
<h1>you is a child<h1>
</c:when>
<c:when test="${param.age>18 and param.age<50 }">
<h1>you is a young person</h1>
</c:when>
<c:when test="${param.age>50}">
<h1>you is a old person</h1>
</c:when>
</c:choose>
<c:forEach>迭代标签
例:
<c:forEach var="book" item="${store.books}" varStatus="status">
<h1>${book.parice}</h1>
</c:forEach>
<c:forEach begin="1" end="5" step="1">
<h1>hello</h1>
</c:forEach>
Core
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
属性设置
<c:set> 设置属性
<c:remove> 移除设置的属性
过程控制
<c:if test="..."> 条件标签只有在test 属性的值为true 是才会执行标签体
例:
<c:if test="${!(empty user.age)}">
<h1>hello</h1>
</c:if>
<c:choose>choose 和when 是组合在一起使用的,有点类似于swith case 的语法。
<c:when test="...">when 也是条件判断标签,test 属性的值为true 是才会执行标签体。
例:
<c:choose>
<c:when test="${param.age<18}">
<h1>you is a child<h1>
</c:when>
<c:when test="${param.age>18 and param.age<50 }">
<h1>you is a young person</h1>
</c:when>
<c:when test="${param.age>50}">
<h1>you is a old person</h1>
</c:when>
</c:choose>
<c:forEach>迭代标签
例:
<c:forEach var="book" item="${store.books}" varStatus="status">
<h1>${book.parice}</h1>
</c:forEach>
<c:forEach begin="1" end="5" step="1">
<h1>hello</h1>
</c:forEach>