免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1057 | 回复: 1
打印 上一主题 下一主题

EL表达式简介 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-01-04 21:24 |只看该作者 |倒序浏览

EL表达式简介







EL表达式


Jstl是sun的标准taglib库,Jstl是标签库和el语言的结合。

el表达式,el表达式的使用方法$和{},比如要取出scope中的hello属性值:${hello}

el表达式的隐含对象pageScope,requestScope,sessionScope,applicationScope,比如${hello}语句首先会从pageScope开始逐个查找scope中的属性,所以要改进该语句为${requestScope.hello}

姓名:${user.username}

年龄:${user.age}

所属组:${user.group.name}

一,el表达式取出map集合中的数据

假设Action中保存map集合:
  1. Map mapvalue=new HashMap();

  2. mapvalue.put(“key1”,”值1”);

  3. mapvalue.put(“key2”,”值2”);

  4. request.setAttribute(“mapvalue”,mapvalue);

  5. jsp上使用el表达式取出map数据:${scope中的属性名.键名}

  6. ${mapvalue.key1}
复制代码
二,el表达式取出数组中的数据

假设Action中有数组

  1. Char[] char={“1”.”2”};

  2. request.setAttribute(“char”,char);

  3. jsp上使用el表达式取出数组数据${scope中属性名[索引值]}

  4. ${char[1]}
复制代码
三,el表达式取出对象数据中的数据

  1. User[] users=new User[10];

  2. for(int i=0;i<10;i++)

  3. {

  4.   User u=new User();

  5.   u.setUsername(“U_”+i);

  6.   users[i]=u;

  7. }

  8. request.setAttribute(“users”,users);
复制代码
Jsp上用el表达式取出对象数组数据${scope中属性名[索引值]}

${users[1].username}

四,el表达式取出list集合中的数据
  1. List list=new ArrayList();

  2. list.add(user1);

  3. list.add(user2);

  4. list.add(user3);

  5. request.setAttribute(“list”,list);
复制代码
jsp上用el表达式取出集合中的数据${scope 中属性名[索引值]}

${list[3].username}

五,el表达式对运算符的支持
  1. 1+2=${1+2}

  2. 10/5=${10/5}

  3. 10 div 5=${10 div 5}

  4. 10%3=${10%3}

  5. 10 mod 3=${10 mod 3}
复制代码
el表达式支持算数运算符和逻辑运算符

六,el表达式的函数

判断值是否为空:

${empty  scope中的属性名}

判断值为非空:

${!empty  scope中的属性名}

论坛徽章:
0
2 [报告]
发表于 2012-01-04 21:24 |只看该作者
谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP