- <%@ page language="java" pageEncoding="UTF-8" import="java.util.*" %>
- <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html:html lang="true">
- <head>
- <html:base />
- <title>MyJsp.jsp</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <!--
- <link rel="stylesheet" type="text/css" href="styles.css">
- -->
- </head>
- <!-- 测试用数据,一般通过request.attribute跳转过来-->
- <%
- List<Map<String,Object>> students = new ArrayList<Map<String,Object>>();
- Map<String,Object> s1 = new HashMap<String,Object>();
- s1.put("name","jim");
- s1.put("age","15");
- students.add(s1);
- Map<String,Object> s2 = new HashMap<String,Object>();
- s2.put("name","lucy");
- s2.put("age","12");
- students.add(s2);
- request.setAttribute("students",students);
- %>
- <body>
- <table>
- <tr>
- <td>姓名
- </td>
- <td>年龄
- </td>
- </tr>
- <!-- loop begin -->
- <c:forEach var="student" items="${students}" >
- <tr>
- <td> <c:out value="${student.name}" default="wang"/>
- </td>
- <td>
- <c:out value="${student.age}" default="wang"/>
- </td>
- </tr>
- </c:forEach>
- <!-- loop end -->
- </table>
- </body>
- </html:html>
- 运行结果如下:
- 姓名 年龄
- jim 15
- lucy 12
- 有了EL表达式确实很方便。微笑
用EL表达式获取List<Map<String,Object>>里面的值
最新推荐文章于 2022-04-18 10:23:49 发布