<%
<%
13 request.setAttribute("name","孤傲苍狼");
14 %>
15 <%--${name}等同于pageContext.findAttribute("name") --%>
16 使用EL表达式获取数据:${name}
17 <hr>
18 <!-- 在jsp页面中,使用el表达式可以获取bean的属性 -->
19 <%
20 Person p = new Person();
21 p.setAge(12);
22 request.setAttribute("person",p);
23 %>
24 使用el表达式可以获取bean的属性:${person.age}
25 <hr>
26 <!-- 在jsp页面中,使用el表达式可以获取bean中的。。。。。。。。。的属性 -->
27 <%
28 Person person = new Person();
29 Address address = new Address();
30 person.setAddress(address);
31
32 request.setAttribute("person",person);
33 %>
34 ${person.address.name}
35 <hr>
36 <!-- 在jsp页面中,使用el表达式获取list集合中指定位置的数据 -->
37 <%
38 Person p1 = new Person();
39 p1.setName("孤傲苍狼");
40
41 Person p2 = new Person();
42 p2.setName("白虎神皇");
43
44 List<Person> list = new ArrayList<Person>();
45 list.add(p1);
46 list.add(p2);
47
48 request.setAttribute("list",list);
49 %>
50
51 <!-- 取list指定位置的数据 -->
52 ${list[1].name}
53
54 <!-- 迭代List集合 -->
55 <c:forEach var="person" items="${list}">
56 ${person.name}
57 </c:forEach>
58 <hr>
59 <!-- 在jsp页面中,使用el表达式获取map集合的数据 -->
60 <%
61 Map<String,String> map = new LinkedHashMap<String,String>();
62 map.put("a","aaaaxxx");
63 map.put("b","bbbb");
64 map.put("c","cccc");
65 map.put("1","aaaa1111");
66 request.setAttribute("map",map);
67 %>
68
69 <!-- 根据关键字取map集合的数据 -->
70 ${map.c}
71 ${map["1"]}
72 <hr>
73 <!-- 迭代Map集合 -->
74 <c:forEach var="me" items="${map}">
75 ${me.key}=${me.value}<br/>
76 </c:forEach>
77 <hr>