注意兩點
JSP中引入標簽---c
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
引入Jar包---jstl
這里寫的是在pom.xml中引入
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
下面看看一個JSP頁面遍歷List的Demo
<%@ 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>
<table border="1" width="500" class="table table-striped table-bordered table-hover table-condensed">
<caption><H3>用戶信息</H3></caption>
<tr><th>用戶名</th><th>密碼</th></tr>
<%-- 要在jsp頁面中使用<c>標簽的foreach遍歷,要注意一下兩點:
1.在jsp開頭引入c標簽
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
2.引入jstl的jar包,可以直接使用lib文件夾也可以使用maven --%>
<c:forEach items="${userList}" var="user">
<tr>
<td>${user.name}</td>
<td>${user.password}</td>
</tr>
</c:forEach>
<!-- 下面的一行是導航條 -->
<tr><td colspan="5">${pageNav}</td></tr>
</table>
</body>
</html>