JSTL标签库
JSTL标签库 全称是 JSP Standard Tag Library jsp标准标签库。 是一个不断完善的开放源代码的JSP标签库。
主要为了替代代码脚本
1.导入jar包
2.使用 taglib 指令引入标签库
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
core核心库使用
<c:set/>用法
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: 26049
Date: 2021/8/28
Time: 17:46
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
保存前:${ requestScope.abc}
<c:set scope="request" var="abc" value="abcValue"/>
保存后:${ requestScope.abc}
</body>
</html>
<c:if/>用法
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: 26049
Date: 2021/8/28
Time: 17:46
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<c:if test="${ 12==12 }">
<h1>12等于12</h1>
</c:if>
</body>
</html>
<c:choose></c:choose>
<c:when></c:when>
<c:otherwise></c:otherwise>
<%--choose是外部标签--%>
<%--when相当于case--%>
<%--oherwise相当于default--%>
foreach标签 遍历循环
<c:forEach begin="1" end="10" var="i"></c:forEach>
相当于
int i = 1; i < 10; i++
遍历数组
<c:forEach items="${ requestScope.arr }" var = "i"></c:forEach>