注意两点
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>