(1)概念
- Expression Language 表达式语言
- 作用:替换和简化jsp中java代码的编写
-
isELIgnored
jsp默认支持el表达式,想要忽略,可以有两种方式
忽略全部isELIgnored
<%@ page contentType=”text/html;charset=UTF-8” language=”java” isELIgnored=”true” %>
忽略部分\${表达式}
<%— false —%> ${3>4} <%—以下会被原义输出到页面上—%> \${3>4}
(2)EL运算符
算术运算符
- /或div %或mod
比较运算符
< > <= >= == !=
逻辑运算符
&& and || or ! not
空运算符empty
判断字符串、集合、数组对象是否为null并且长度是否为0
(3)获取值
- 只能从域对象中获取值
- pageScope >>> pageContext
- requestScope >>> request
- sessionScope >>> session
- applicationScope >>> application(ServletContext)
- ${域名.键名}
- ${键名}:没有域名,则默认依次从小到大pageScope > requestScope > sessionScope > applicationScope 中寻找
字符串
<%
request.setAttribute("name","zhangsan");
%>
<%--取出域对象中的值--%>
${requestScope.name}
<%--为empty的话不会显示,但不会报错--%>
${pageScope.xx}
<%--${sessionScope.xx}--%>
<%--${applicationScope.xx}--%>
获取对象属性
获取对象的属性,本质上是去找对应的getXxx()方法 ``` <%
User user = new User(); user.setName(“tom”); user.setAge(20); request.setAttribute(“user”,user);
%>
<%—会打印User类的tostring()方法—%> ${requestScope.user}
<%—访问对象的属性 回去寻找getName()这个方法—%> ${requestScope.user.name}
<%—访问对象的desc属性,就会去找getDesc()这个方法—%> ${requestScope.user.desc}
<%—${sessionScope.xx}—%> <%—${applicationScope.xx}—%>
<a name="j7Ny9"></a>
#### List
- ${域名城.键名[索引]}
<%
List list = new ArrayList();
list.add("a");
list.add("b");
list.add("c");
request.setAttribute("list",list);
%>
${requestScope.list}
${requestScope.list[0]}
<%—越界什么都不会显示—%>
${requestScope.list[10]}
<a name="327Yg"></a>
#### Map
- ${域名城.键名.key}
- ${域名城.键名["key"]}
<%
Map map = new HashMap();
map.put("name","tom");
map.put("age","20");
request.setAttribute("map",map);
%>
${requestScope.map}
${requestScope.map.name}
${requestScope.map[“age”]}
<a name="37uJl"></a>
### (4)empty
<%
List list = new ArrayList();
// list.add(“a”); // list.add(“b”); // list.add(“c”);
request.setAttribute("list",list);
%>
<%—true—%>
${empty requestScope.list}
${not empty requestScope.list}
<a name="2GodK"></a>
### (5)隐式对象
- el表达式中有11个隐式对象
- pageContext可以获取其它八个内置对象
${pageContext.request}
${pageContext.request.contextPath}
```