获取域中List集合和Map集合存储的值
List集合:
${域名称.键名[索引]}
<% User user = new User(); user.setName("张三"); user.setAge(30); user.setBirthday(new Date()); 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(30); user.setBirthday(new Date()); HashMap map = new HashMap(); map.put("sname","张三"); map.put("gender","男"); map.put("user",user); request.setAttribute("map",map); %> <h3>EL获取map中的值</h3> ${map.sname}<br> ${map["gender"]}<br> ${map.user.name}
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}
虚拟目录为空,所以获取的也是空
标签:Map,list,运算符,获取,集合,pageContext,empty From: https://www.cnblogs.com/xjw12345/p/16590513.html