3.获取对線、 List 集合、 Map 集合的值
1.对線:${域名称,键名.属性名}本质上会去调用对線的 getter 方法
2. List 集合:${域名称。键名[索引]}
List list = new ArrayList (); list . add (" aaa "); list . add (" bbb "); list . add ( user ); request . setAttribute ( s :" list ", list );
<h3> el 获取 List 值</h3> ${1ist}< br > ${ list [0]}< br > ${ list [1]}< br > ${ list [10]}< br > ${ list [2]. name }
3.Map集合:${域名称。键名. key 名称}
Map map = ncw HashMap (); map . put (" sname ","李四"); map . put (" gender ","男"); map . put (" user ", user ); request . setAttribute ( s :" map ", map );
<h3> el 获取 Map 值</h3> ${ map . gender }< br > ${ map [" gcndcr "]}< br > ${ map . user . name }
EL _ empty 运算符&隐式对象 pageContext
算符: empty
功能:用判断字符串、集合数组对家是否为nu11或著长度是否为0
$( empty list }:判所字符串、集合、数组对線是否为nu11或者长度为0
${ not empty str :表示判所学符串、集合、故组对象是否不null并且长度>0
<h4> empty 运算符</h4><% String str =""; request . setAttribute ( s :" str ", str ); List list = new ArraList(); request . setAttribute ( s :"1ist", list ); %> ${ not empty str } ${ not empty list }
3.隐式对象
el 表达式中有11个试对象pageContext :
获取 jsp 其他八个内置对象
${ pageContext . request . contextPath }:动态获取虚拟目录
<$@ page contcntTypc =" text / html ; charsct = UTF -8"1anguagc=" java ”%>< html > < head > < title > el 隐式对象</ title ></ hcad > < body > ${ pageContext . request }< br > <h4>在 jsp 页面动态获取虛拟目录</h4> ${ pageContext . request . contextPath } %> </ body > </ html >