首先导入依赖:
<!-- jstl表达式依赖 --> <!-- https://mvnrepository.com/artifact/javax.servlet/jstl --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <!-- standard标签库依赖 --> <!-- https://mvnrepository.com/artifact/taglibs/standard --> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency>
EL表达式: ${ }
获取数据
执行运算
获取web开发的常用对象
JSP标签:
<jsp:forward page="index.jsp"> <jsp:param name="name" value="allen"/> <jsp:param name="age" value="22"/> </jsp:forward>
JSTL标签:
JSTL标签库的使用就是为了弥补HTML标签的不足;它自定义许多标签,可以供我们使用,标签的功能和Java代码一样!
核心标签:
核心标签是最常用的 JSTL标签。引用核心标签库的语法如下:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
常用:
<c:if>
<c:if test="<boolean>" var="<string>" scope="<string>"> ... </c:if>
<c:choose>, <c:when>, <c:otherwise>
<c:choose> <c:when test="<boolean>"> ... </c:when> <c:when test="<boolean>"> ... </c:when> ... ... <c:otherwise> ... </c:otherwise> </c:choose>
<c:foreach>
<c:forEach items="<object>" begin="<int>" end="<int>" step="<int>" var="<string>" varStatus="<string>"> ... </c:forEach>