maven库
JavaServer Pages Standard Tag Library (1.1 ) ,它的中文名称为 JSP 标准标签函数库。JSTL 是一个标准的已制定好的标签库,可以应用于各种领域,如:基本输入输出、流程控制、循环、XML 文件剖析、数据库查询及国际化和文字格式标准化的应用等。从表 7-1 可以知道,JSTL 所提供的标 签函数库主要分为五大类:
(1)核心标签库 (Core tag library)
(2)I18N 格式标签库 (I18N-capable formatting tag library)
(3)SQL 标签库 (SQL tag library)
(4)XML 标签库 (XML tag library)
(5)函数标签库 (Functions tag library) 表 。
如何使用,在项目引入依赖jar包
image.png
jsp中导入标签库
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
使用
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
年龄 :${ age }
<!-- if(条件){} -->
<!-- c:if <c:if test="条件"></c:if>-->
<c:if test="${ age > 18}">
成年
</c:if>
<c:if test="${ age <= 18}">
未成年
</c:if>
<!--
List<String> list;
for(;;i+=2)
for(String str :list){}
-->
<!-- c:forEach -->
<!-- List<String> -->
<c:forEach items="${ strList }" var="str" >
${ str }
</c:forEach>
<hr>
<!-- List<Userinfo> -->
<c:forEach items="${ userList }" var="user" >
${ user.username },${ user.password }
</c:forEach>
<hr>
<!-- Map<String,String> -->
<c:forEach items="${ map }" var="map">
${ map.key },${ map.value }
</c:forEach>
<hr>
<!-- Map<String,Userinfo> -->
<c:forEach items="${ userMap }" var="map">
${ map.key },${ map.value.username },${ map.value.password }
</c:forEach>
<hr>
<!-- List<Map<String,Userinfo>> -->
<c:forEach items="${ listMap }" var="map">
<c:forEach items="${ map }" var="entry">
${ entry.key },${ entry.value.username },${ entry.value.password }
<br>
=====================
<br>
</c:forEach>
</c:forEach>
<hr>
<c:forEach items="${ listMap1 }" var="map">
${ map.java1 }
</c:forEach>
<!-- c:choose -->
<c:choose>
<c:when test="${ age <= 18 }">
未成年
</c:when>
<c:when test="${ age > 70 }">
老年
</c:when>
<c:otherwise>
中年
</c:otherwise>
</c:choose>
<a href="${pageContext.request.contextPath }/jstltest">a</a>
</body>
</html>