前言
:实践是检验真理的唯一标准
获取数据
获取常量
字符型:${"我爱EL"}
数值型:${520}
布尔值:${true}
结果:
我爱EL
520
true
获取变量
<%
//el表达式只能获取到保存到作用于里的变量
//el表达式如果没有获取变量,那就啥也不返回
//el表达式获取变量,是在四大作用域中从小到大依次寻找
//setAttribute("属性名","属性值");
pageContext.setAttribute("name","El1");
request.setAttribute("name","El2");
pageContext.setAttribute("age","22");
String email = "123@form.com";
%>
name = ${name}
age = ${age}
email=${eamil}
结果是:
获取数组中的数据
<%
String[] array = {"application","session","request","page"};
pageContext.setAttribute("array",array);
%>
array[2] = ${array[2]}
获取集合中的数据
<%
List<String> list = new ArrayList<String>();
list.add("1");
list.add("2");
list.add("3");
list.add("4");
pageContext.setAttribute("list",list);
%>
list[2] = ${[list[2]};
获取map中的数据
<%
Map<String,String> map = new HashMap<String,String>();
map.put("name","EL");
map.put("age","100");
pageContext.setAttribute("map",map);
%>
name=${map.name}
age=${map["age"]}
结果是:
运算
//算数运算
1+1 = ${1+1}
1*2 = ${1*2}
//关系运算
1 & lt 2 = &{1 lt 2}
1 & gt 2 = &{1 gt 2}
//逻辑运算
true && true = ${ true and true}
false && false = ${ false and false }
!true = ${ not true }
//三元运算
1<2?"1<2":"1>2" = ${ 1<2?"1<2":"1>2" }