您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
13_EL_获取域中存储的值_List集合&Map集合值
发布时间:2022-09-11 15:49:33编辑:雪饮阅读()
在el中获取list集合中的值也是可以的,并且数组越界只是不显示而不至于报错。支持普通值,也支持对象值。
在el中获取map集合中的值也是可以的,支持普通值,也支持对象值,支持点分语法也支持关联索引数组访问语法。
实例如:el3.jsp:
<%@ page import="package1.User" %>
<%@ page import="java.util.*" %>
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2022/9/10
Time: 13:09
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
//list集合
User user=new User();
user.setName("kasumi");
user.setAge(24);
user.setBirthday(new Date());
List list=new ArrayList();
list.add("list_v_1");
list.add("list_v_2");
list.add(user);
request.setAttribute("list",list);
//map集合
User user2=new User();
user2.setName("霞");
user2.setAge(28);
user2.setBirthday(new Date());
Map map=new HashMap();
map.put("map_key1","momiji");
map.put("map_key2",user2);
request.setAttribute("map",map);
%>
<h1>el获取list值</h1>
list:${list}<br/>
list0:${list[0]}<br/>
list1:${list[1]}<br/>
list2:${list[2]}<br/>
<!--
list集合中元素值为对象也支持获取
-->
list2.name:${list[2].name}<br/>
<!--
el表达式中获取数组越界的索引的值时候,不会报错,就不显示而已
-->
list3:${list[3]}<br/>
<h1>el获取map值</h1>
map.map_key1:${map.map_key1}<br/>
<!--el获取map集合元素值时候有两种方式,这也是一种方式,不过应该用的比较少吧,对于这种方式-->
map.["map_key1"]:${map["map_key1"]}<br/>
<!--map集合元素中的值为对象时候也支持获取-->
map.map_key2.name:${map.map_key2.name}
</body>
</html>
关键字词:EL,获取,域,中,存储,值,List,集合,Map