zoukankan      html  css  js  c++  java
  • EL表达式取值

    转自:http://hi.baidu.com/fevelen/item/5b0484510c059ad8d48bacb9

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

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

    属性值:${hello}

    对象值

    姓名:${user.username}

    年龄:${user.age}

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

    map集合

    假设Action中保存map集合:

    Map mapvalue=new HashMap();

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

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

    request.setAttribute(“mapvalue”,mapvalue);

    ${mapvalue.key1}

    数组

    假设Action中有数组

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

    request.setAttribute(“char”,char);

    ${char[1]}

    数组中的对象

    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);

    ${users[1].username}

    list集合

    List list=new ArrayList();

    list.add(user1);

    list.add(user2);

    list.add(user3);

    request.setAttribute(“list”,list);

    ${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中的属性名}

  • 相关阅读:
    UML_04_时序图
    UML_03_类图
    UML_02_概述
    UML_00_资源帖
    UML_01_画图工具
    SpringCloud_00_资源帖
    Idea_03_常用快捷键
    Idea_02_常用配置
    Idea_01_安装与激活
    Codeforces命令行工具
  • 原文地址:https://www.cnblogs.com/summer520/p/3435659.html
Copyright © 2011-2022 走看看