<% @page import = "java.util.Map" %> |
<% @page import = "java.util.HashMap" %> |
<% @page import = "java.util.List" %> |
<% @page import = "java.util.ArrayList" %> |
<% @page import = "am_cn.itcast.domain.Student" %> |
<%@ page language= "java" contentType= "text/html; charset=UTF-8" |
pageEncoding= "UTF-8" %> |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > |
<html> |
<head> |
<meta http-equiv= "Content-Type" content= "text/html; charset=UTF-8" > |
<title>Insert title here</title> |
</head> |
<body> |
|
<!-- 访问javabean的属性、访问list集合、访问map集合、访问数组 --> |
|
<% |
|
Student student = new Student( "陈毛毛" , 18 , "上海" ); |
|
request.setAttribute( "s1" , student); |
|
%> |
|
${s1 } |
<!-- 想 取出 student 的 其他的 信息: 姓名, 年龄, 城市 --> |
<!-- 在 el 表达式 中 都是 调用 了 其 getXXX方法 --> |
${s1.name } |
${s1.age } |
${s1.city } |
|
<hr/> |
<!-- 访问 数组 --> |
<% |
String[] names = { "西门庆" , "西门崔雪" , "西门抽血" , "西门抽筋" }; |
request.setAttribute( "names" , names); |
|
%> |
${names } |
${names[ 0 ] } |
${names[ 1 ] } |
${names[ 2 ] } |
${names[ 3 ] } |
|
<!-- 取出 list 集合中的 数据 --> |
|
<% |
List list = new ArrayList(); |
list.add( "aaa" ); |
list.add( "bbb" ); |
list.add( "ccc" ); |
request.setAttribute( "list" , list); |
%> |
|
${list } |
${list[ 0 ] } <!-- list.get(O) --> |
${list[ 1 ] } <!-- list.get( 1 ) --> |
${list[ 2 ] } |
<hr/> |
<!-- 取出 map 中的 数据 --> |
<% |
Map map = new HashMap(); |
|
map.put( "aaa.ddd" , "111" ); |
map.put( "bbb" , "222" ); |
map.put( "ccc" , "333" ); |
|
request.setAttribute( "map" , map); |
%> |
${map } <!-- { key=value,key=value} --> |
${map[ "aaa" ] } |
${map[ "bbb" ] } |
${map[ "ccc" ] } |
|
${map.aaa.ddd } |
${map[ "aaa.ddd" ] } |
|
<!-- 可以 写成${map.aaa } , 就可以 写成 ${map[ "ccc" ] } ,但是 反过来 不行 --> |
|
<!-- |
练习 ,请取出 学生 姓名 ,年龄, 城市 |
--> |
<% |
List list1 = new ArrayList(); |
list1.add( new Student( "李寒" , 18 , "上海" )); |
list1.add( new Student( "孙在驰" , 19 , "香港" )); |
list1.add( new Student( "李羿成" , 17 , "东京" )); |
|
request.setAttribute( "student" , list1); |
%> |
|
${student[ 0 ].name } |
${student[ 0 ].age } |
${student[ 0 ].city } |
|
</body> |
</html> |