EL_获取域中存储的值List集合&Map集合值
List集合:${域名称.键名[索引]}
<% User user = new User(); user.setName("张三"); user.setAge(23); user.setBirthday(new Date()); request.setAttribute("u", user); List list = new ArrayList(); list.add("aaa"); list.add("bbb"); list.add(user); request.setAttribute("list", list); %> <h3>el获取List值</h3> ${list}<br> ${list[0]}<br> ${list[1]}<br> ${list[2].name}<br>
Map集合:
${域名称.键名.key名称}
${域名称.键名.["key名称"]}
<% User user = new User(); user.setName("张三"); user.setAge(23); user.setBirthday(new Date()); request.setAttribute("u", user); Map map = new HashMap(); map.put("sname", "李四"); map.put("gender", "男"); map.put("user", user); request.setAttribute("map", map); %> <hr> <h3>el获取Map值</h3> ${map.gender}<br> ${map["gender"]}<br> ${map.user.name}<br>
EL_empty运算符和隐式对象pageContext
空运算符:empty
功能:用于判断字符串、集合、数组对象是否为null并且长度是否为0
${empty list}:判断字符串、集合、数组对象是否为null 或者长度为0
${not empty list}:判断字符串、集合、数组对象是否不为null并且长度大于0
<% String str = ""; request.setAttribute("str",str); String str1 = null; request.setAttribute("str1",str1); List list = new ArrayList(); request.setAttribute("list",list); %> <h3>empty运算符</h3> ${empty str} ${empty str1} ${not empty list}
隐式对象
el表达式中有11个隐式对象
pageContext:
获取jsp其他八个内置对象
${pageContext.request.contextPath}:动态获取虚拟目录
${pageContext.request} <h3>在jsp页面动态获取虚拟目录</h3> ${pageContext.request.contextPath}
虚拟目录为空,所以获取的也是空
标签:EL,list,运算符,获取,集合,pageContext,empty From: https://www.cnblogs.com/qihaokuan/p/16999601.html