EL:Expression Language

Expression Language,可以替代JSP页面中的Java代码

servlet(增加数据)->jsp(显示数据)

传统的 在JSP中用java代码显示数据的弊端:类型转换、需要处理null、代码参杂--->EL

EL示例:
${requestScope.student}<br/>
${requestScope.student.sno}<br/>
${requestScope.student.sname}<br/>
${requestScope.student.address}<br/>
${requestScope.student.address.homeAddress}<br/>
${requestScope.student.address.schoolAddress}<br/>
${域对象.域对象中的属性.属性.属性.级联属性}<br/>
El操作符:
.操作符 ---使用方便
[""]操作符---功能强大;可以包含特殊字符(.、-),可以访问数组,获取变量值 例如存在变量name 则可以${requestScope[name]}
${requestScope["student"]["address"]["schoolAddress"]}<br/>//单引号亦可

获取map属性
Map<String, Object> map=new HashMap<>();
map.put("cn", "中国");
map.put("us", "美国");
request.setAttribute("map", map);
${requestScope.map.cn}<br/>
${requestScope["map"]["us"]}<br/>
关系运算符 逻辑运算符


Empty运算符:判断一个值 null、不存在-->true


EL表达式的隐式对象(不需要new就能使用的对象,自带的对象)
a.作用域访问对象(EL域对象):pageScope requestScope sessionScope appliactionScope
如果不指定域对象,则默认会根据 从小到大的顺序 以此取值
b.参数访问对象:获取表单数据(超链接中传的值,地址栏中的值 )(request.getParameter()、request.getParameterValue())
${param} ${paramValues}

c.JSP隐式对象:pageContext
在jsp中可以通过pageContext获取其他的jsp隐式对象;因此如果要在EL中使用JSP隐式对象,就可以通过pageContext间接获取
例如${pageContext.request}
${pageContext.方法名}${pageContext.session}
可以使用此方法,级联获取方法
${pageContext.resquest.serverPort}
${pageContext.方法名去掉()和get并且将首字母小写}

原文地址:https://www.cnblogs.com/mayouyou/p/13122165.html