EL表达式
来源:互联网 发布:数据库建库 编辑:程序博客网 时间:2024/06/07 14:24
EL表达式
1、EL概述和基本语法
EL表达式:expression language 表达式语言
要简化jsp中java代码开发。
它不是一种开发语言,是jsp中获取数据的一种规范
2、EL的具体功能
a、获取数据
EL表达式只能获取存在4个作用域中的数据
EL获取对于null这样的数据,在页面中表现为空字符串
${u.name} == u.getName()方法
点(.) 运算符相当于调了getter方法,点后页面跟的是属性名。
<% //Student stu = (Student)request.getAttribute("student");//null //out.print(stu);//null //Student stu = (Student)session.getAttribute("student"); // out.print(stu.getName());// null.getName(); %> ${student }<!-- 相当于pageContext.findAttribute()方法,会依次从四个作用域中查找,不存在的显示"" --> ${student.name}<!-- 属性导航 内部调用了getName()方法--> //属性导航 ${student.addr.district}
[]运算符:点能做的,它也能做; 它能做的,点不一定能做
<% List<String> list = new ArrayList<String>(); list.add("哈哈1"); list.add("哈哈2"); list.add("哈哈3"); list.add("哈哈4"); request.setAttribute("jihe", list); Map<String,String> map = new HashMap<String,String>(); map.put("name", "lisi"); map.put("age","20"); map.put("sex","男"); pageContext.setAttribute("mapjihe", map); %> ${jihe[1] } ${mapjihe} ${mapjihe.age} ${mapjihe["sex"]}
b、运算
empty
判断null,空字符串和没有元素的集合(即使集合对象本身不为null)都返回true
<% String s1 = ""; request.setAttribute("s1", s1); String s2 = null; request.setAttribute("s2", s2); String s3 = "hello"; request.setAttribute("s3", s3); List<String> list1 = new ArrayList<String>(); request.setAttribute("jihe", list1); List<String> list2 = new ArrayList<String>(); list2.add("呵呵"); list2.add("哈哈"); list2.add("嘻嘻"); request.setAttribute("jihe2", list2); int sex = 1; request.setAttribute("gender", sex); %> ${empty s1} --true ${empty s2}--true ${empty s3}--false ${empty jihe}--true ${empty jihe2}--false ${empty jihe2? "你太抠了,什么都没买":"购物车的商品如下:"}
三元运算符
<input type="radio" name="sex" ${gender==1 ?"checked='checked'":""} >男 <input type="radio" name="sex" ${gender==0 ?"checked='checked'":""}>女
c、隐式对象:11个
1 0
- 【EL】EL表达式
- EL表达式
- EL表达式
- EL表达式
- EL表达式
- EL表达式
- EL表达式
- EL表达式
- EL表达式
- el表达式
- EL表达式
- EL表达式
- EL表达式
- el表达式
- el 表达式
- EL表达式
- EL表达式
- EL表达式
- JS-如何使用DOM操纵样式表
- 字典序问题
- 比特同步和帧同步的区别
- 【POJ3393】Lucky and Good Months by Gregorian Calendar
- hdu 5878 I Count Two Three 丑数 二分
- EL表达式
- tp 学习基础
- poj 1011 Sticks
- HDU 2047 - 阿牛的EOF牛肉串(递推)
- [OICamp 2016 Day 1][JZOJ4773]凸包
- C++实现数据结构-队列
- 初识bitset
- hdu5894 hannnnah_j’s Biological Test
- centos6.5环境Redis下载及编译安装