<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>forEach</title>
</head>
<body>
<%-- 相当于for(int i = 0; i<10; i++)--%>
<c:forEach var="i" begin="1" end="10" step="2">
${i}
</c:forEach>
<%
List<String> list = new ArrayList<>();
for (int i = 0; i<10;i++){
list.add("A:" + i);
}
pageContext.setAttribute("li",list);
// 相当于:
// for (String li : list){
// out.print(li);
// }
%>
<c:forEach items="${li}" var="item">
${item}
</c:forEach>
<table align="center" width="800" border="1" style="border-collapse: collapse">
<tr>
<th>名称</th>
<th>当前成员的下标</th>
<th>当前成员的循环数</th>
<th>是否第一次被循环</th>
<th>是否最后一次循环</th>
</tr>
<c:forEach items="${li}" var="item" varStatus="itemp">
<tr>
<td>${item}</td>
<td>${item}</td>
<td>${item}</td>
<td>${item}</td>
<td>${item}</td>
</tr>
</c:forEach>
</table>
<%
List<User> userList = new ArrayList<>();
for (int i = 0;i<3;i++){
User user1 = new User(1,"gagu","duygauhi");
userList.add(user1);
request.setAttribute("userList",userList);
}
%>
<c:if test="${!empty userList}">
<table align="center" width="800" border="1" style="border-collapse: collapse">
<tr>
<th>用户编号</th>
<th>用户名称</th>
<th>用户密码</th>
<th>用户操作</th>
</tr>
<c:forEach items="${userList}" var="user">
<tr>
<td>${user.userId}</td>
<td>${user.uname}</td>
<td>${user.upwd}</td>
<td><button>修改</button></td>
</tr>
</c:forEach>
</c:if>
</body>
</html>