2020.04.25 JSTL+EL练习案例

<%@ page import="com.aojie.domain.User" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Date" %><%--
Created by IntelliJ IDEA.
User: AoJie
Date: 2020/4/25
Time: 22:00
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
List<User> list=new ArrayList<>();
list.add(new User("zhangsan",21,new Date()));
list.add(new User("wanger",22,new Date()));
list.add(new User("mazi",21,new Date()));
request.setAttribute("list",list);
%>
<table border="1" width="500px" align="center">
<tr>
<th>编号</th>
<th>姓名</th>
<th>年龄</th>
<th>日期</th>
</tr>
<%-- 数据行--%>
<c:forEach items="${list}" var="user" varStatus="s">
<c:if test="${s.count%2==0}">
<tr class="tr" bgcolor="blue">
<td>${s.count}</td>
<td>${user.name}</td>
<td>${user.age}</td>
<td>${user.strDate}</td>
</tr>
</c:if>
<c:if test="${s.count%2==1}">
<tr class="tr" bgcolor="yellow">
<td>${s.count}</td>
<td>${user.name}</td>
<td>${user.age}</td>
<td>${user.strDate}</td>
</tr>
</c:if>
</c:forEach>
</table>
</body>
</html>
posted @ 2020-04-25 22:25  ByLir  阅读(223)  评论(0)    收藏  举报