EL用法

<%@ page import=“cn.laowang.servlets.Address”%>
<%@ page import=“cn.laowang.servlets.User”%>
<%@ page import=“java.util.*”%>
<%@ page language=“java” contentType=“text/html; charset=UTF-8”
pageEncoding=“UTF-8” isELIgnored=“false” %>
<%–
EL(Expression Language)表达式
语法:${ }
–%>
<%
int a = 1234;
pageContext.setAttribute(“a”, a);
pageContext.setAttribute(“scope”, “pageContext”);
request.setAttribute(“scope”, “request”);
session.setAttribute(“scope”, “session”);
application.setAttribute(“scope”, “application”);
List list = new ArrayList();
list.add(“aaa”);
list.add(“bbb”);
list.add(“ccc”);
list.add(“ddd”);
request.setAttribute(“list”, list);
Map map = new HashMap();
map.put(“name”, “zhangsan”);
map.put(“gender”, “男”);
map.put(“address”, “天河区”);
request.setAttribute(“map”, map);
User user = new User(“zhangsan”,“kahdfasd”,“张三”,“男”,20,new Address(“广东省”,“广州市”,“天河区”));
request.setAttribute(“user”, user);
request.setAttribute(“aaa”, “”);
request.setAttribute(“bbb”, null);
request.setAttribute(“ccc”, new ArrayList());
request.setAttribute(“ddd”, new HashMap());

%>

Insert title here

EL表达式从哪里取值?一般情况下,从作用域对象中取值

${a}

EL表达式优先从哪个作用域对象中取值?默认情况下从最小作用域取值

${scope}

EL表达式从指定作用域对象中取值:pageScope、requestScope、sessionScope、applicationScope

${pageScope.scope} --- ${requestScope.scope} --- ${sessionScope.scope} --- ${applicationScope.scope}

EL表达式可以解析什么类型的数据?基本数据类型、对象类型、复合对象类型、Map、List

${list[2]} --- ${map.address} --- ${user.realname} --- ${user.addr.town}

EL也可以取请求参数的数据:param、paramValues

${param.name} --- ${paramValues.fav[2]}

EL表达式的[]内也可以做EL表达式的解析

${user.realname} --- ${user["realname"]} --- ${user[param.type]}

EL表达式可以做为空判断:空字符串、null、空map、空list这几个值为true

${empty aaa} --- ${empty bbb} --- ${empty ccc} --- ${empty ddd} --- ${empty scope}

EL表达式可以做基本的逻辑运算,和数学运算

EL表达式没有字符串拼接的概念,也没有字符的概念
${5+4} --- ${5-4} --- ${5*4} --- ${5/4} --- ${5%4} --- ${5+"4"} --- ${5>4} --- ${5 < 4} --- ${5>=4} --- ${5 le 4} --- ${5 eq 4}

EL表达式中pageContext可以获取pageContext作用域对象本身

${pageContext}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值