zoukankan      html  css  js  c++  java
  • 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集合:

    Map mapvalue=new HashMap();

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

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

    request.setAttribute(“mapvalue”,mapvalue);

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

    ${mapvalue.key1}

    二,el表达式取出数组中的数据

    假设Action中有数组

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

    request.setAttribute(“char”,char);

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

    ${char[1]}

    三,el表达式取出对象数据中的数据

    User[] users=new User[10];

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

    {

      User u=new User();

      u.setUsername(“U_”+i);

      users[i]=u;

    }

    request.setAttribute(“users”,users);

    Jsp上用el表达式取出对象数组数据${scope中属性名[索引值]}

    ${users[1].username}

    四,el表达式取出list集合中的数据

    List list=new ArrayList();

    list.add(user1);

    list.add(user2);

    list.add(user3);

    request.setAttribute(“list”,list);

    jsp上用el表达式取出集合中的数据${scope 中属性名[索引值]}

    ${list[3].username}

    五,el表达式对运算符的支持

    1+2=${1+2}

    10/5=${10/5}

    10 div 5=${10 div 5}

    10%3=${10%3}

    10 mod 3=${10 mod 3}

    el表达式支持算数运算符和逻辑运算符

    六,el表达式的函数

    判断值是否为空:

    ${empty  scope中的属性名}

    判断值为非空:

    ${!empty  scope中的属性名}

  • 相关阅读:
    21-while里的break简单用法
    20-使用while循环求从1累加至100的值
    19-random猜数
    18-random猜数,直到正确。
    17-简化后的石头剪刀布
    16-if实现石头剪刀布
    生成随机数
    转换数字的进制(Integer、Long)
    数字的舍入
    格式化数字
  • 原文地址:https://www.cnblogs.com/jinzhengquan/p/1953150.html
Copyright © 2011-2022 走看看