JSP和JSTL视图解析器

JSP和JSTL视图解析器

JSP和JSTL视图解析器

使用JSTL

JSP和JSTL视图解析器

users.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 2 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 3 <!DOCTYPE html>
 4 <html>
 5     <head>
 6         <title>JSTL Demo</title>
 7     </head>
 8     
 9     <body>
10         <table>
11             <thead>
12             <tr>
13                 <th>ID</th>
14                 <th>UserName</th>
15                 <th>Name</th>
16                 <th>Age</th>
17             </tr>
18             </thead>
19             <tbody>
20                 <c:forEach items="${users}" var="user">
21                     <tr>
22                         <td>${user.id}</<td>
23                         <td>${user.userName}</<td>
24                         <td>${user.name}</<td>
25                         <td>${user.age}</<td>
26                     </tr>
27                 </c:forEach>
28             </tbody>
29         </table>
30     </body>
31 </html>

封装集合对象

JSP和JSTL视图解析器

效果:

JSP和JSTL视图解析器