JSTL 核心标签库
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
单条件判断 (if)
${pageContext.setAttribute("score","A")}
<c:if test="${score eq 'A'}">
优秀
</c:if>
多条件判断(if else if )
<c:choose>
<c:when test="${score eq 'A'}">优秀</c:when>
<c:when test="${score eq 'B'}">良好</c:when>
<c:when test="${score eq 'C'}">及格</c:when>
<c:when test="${score eq 'D'}">不及格</c:when>
<c:otherwise>非法成绩</c:otherwise>
</c:choose>
循环遍历( for )
<%
ArrayList<String> list = new ArrayList();
list.add("aa");
list.add("bb");
list.add("cc");
pageContext.setAttribute("list",list);
%>
<c:forEach items="${list}" var="str">
${str} <br>
</c:forEach>
扩展阅读文件 链接: https://pan.baidu.com/s/1x6hYrwx6TReVYJnC3_pNLg 提取码: qcnm –来自百度网盘超级会员v4的分享
|