3. 获取对象、List集合、Map集合的值
1. 对象:${域名称.键名.属性名}
本质上会去调用对象的getter方法
2.List集合:${域名称.键名[索引]}
3. Map集合:
${域名称.键名.key名称}
${域名称.键名["key名称"]}
3. 隐式对象:
el表达式中有11个隐式对象
pageContext:
获取jsp其他八个内置对象
${pageContext.request.contextPath}:动态获取虚拟目录
<%@ page import="java.util.List" %> <%@ page import="java.util.ArrayList" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <h3>算数运算符</h3> ${3 + 4}<br> ${3 / 4}<br> ${3 div 4}<br> ${3 % 4}<br> ${3 mod 4}<br> <h3>比较运算符</h3> ${3 == 4}<br> <h3>逻辑运算符</h3> ${3 > 4 && 3 < 4}<br> ${3 > 4 and 3 < 4}<br> <h4>empty运算符</h4> <% String str = ""; request.setAttribute("str",str); List list = new ArrayList(); request.setAttribute("list",list); %> ${not empty str} ${not empty list} </body> </html> ----------------------------- <h3>el获取对象中的值</h3> ${requestScope.u}<br> <%-- * 通过的是对象的属性来获取 * setter或getter方法,去掉set或get,在将剩余部分,首字母变为小写。 * setName --> Name --> name --%> ${requestScope.u.name}<br> ${u.age}<br> ${u.birthday}<br> ${u.birthday.month}<br> ${u.birStr}<br> <h3>el获取List值</h3> ${list}<br> ${list[0]}<br> ${list[1]}<br> ${list[10]}<br> ${list[2].name} <h3>el获取Map值</h3> ${map.gender}<br> ${map["gender"]}<br> ${map.user.name} --------------- <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>el隐式对象</title> </head> <body> ${pageContext.request}<br> <h4>在jsp页面动态获取虚拟目录</h4> ${pageContext.request.contextPath} <% %> </body> </html>
标签:775,EL,el,list,运算符,获取,Map,pageContext From: https://www.cnblogs.com/agzq/p/17113531.html