EL简易实践知识

前言

:实践是检验真理的唯一标准

获取数据

获取常量

字符型:${"我爱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" }
  
   
    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值