首页 > 其他分享 >EL获取域中存储的值List集合&Map集合值和EL empty运算符&隐式对象pageContext

EL获取域中存储的值List集合&Map集合值和EL empty运算符&隐式对象pageContext

时间:2022-08-16 09:44:40浏览次数:39  
标签:EL map list 运算符 集合 Map pageContext empty

EL获取域中存储的值List集合&Map集合值

3.获取对象、List集合、Map集合的值

  1.对象:${域名称.键名.属性名}

    本质上会去调用对象的getter方法

  2.List集合:${域名称.键名[索引]}

  3.Map集合:

    ${域名称.键名.key名称}

    ${域名称.键名["key名称"]}

<%
    User user = new User();
    user.setName("张三");
    user.setAge(23);
    user.setBirthday(new Date());

    request.setAttribute("u",user);

    List list = new ArrayList<>();
    list.add("aaa");
    list.add("bbb");
    list.add(user);
    request.setAttribute("list",list);


    Map map = new HashMap();
    map.put("sname","李四");
    map.put("gender","男");
    map.put("user",user);
    request.setAttribute("map",map);

%>
<h3>el获取List值</h3>
${list}<br>
${list[0]}<br>
${list[1]}<br>
${list[10]}<br>
${list[2].name}

<h3>el获取Map值</h3>
${map.gender}<br>
${map["gender"]}<br>
${map.user.name}

EL empty运算符&隐式对象pageContext

空运算符:empty

      功能:用于判断字符串、集合、数组对象是否为null或者长度是否为0

      ${empty list}:判断字符串、集合、数组对象是否为null或者长度为0

      ${not empty str}:判断字符串、集合、数组对象是否不为null并且长度>0

<h3>empty运算符</h3>
<%
    String str = "abc";
    request.setAttribute("str",str);

    List list = new ArrayList<>();
//    list.add("aaa");
//    list.add("bbb");
    request.setAttribute("list",list);
%>
${not empty str}<br>

${not empty list}<br>

隐式对象pageContext

el表达式中有11个隐式对象

pageContext:

  获取jsp其他八个内置对象

    ${pageContext.request.contextPath}:动态获取虚拟目录

<body>

    ${pageContext.request}<br>
    <h3>动态获取虚拟目录(jsp页面获取)</h3>
    ${pageContext.request.contextPath}<br>

</body>

 

搜索

复制

标签:EL,map,list,运算符,集合,Map,pageContext,empty
From: https://www.cnblogs.com/pengtianyang/p/16590490.html

相关文章

  • .NET性能优化-快速遍历List集合
    简介System.Collections.Generic.List<T>是.NET中的泛型集合类,可以存储任何类型的数据,因为它的便利和丰富的API,在我们平时会广泛的使用到它,可以说是使用最多的集合类。在......
  • Navicat 1451 Cannot delete or update aparent row: a foreign key constraint fails
    如下图,全选后删除不了  原因:外键约束导致的. 解决:先将外键所在行删除,ctrl+s,再全选中删除. ......
  • 持续集成:Jenkins Pipeline语法介绍[转]
    Pipeline在Unix/Linux系统中经常用到,Pipeline将一个命令/程序/进程的输出发送到另一个命令/程序/进程,以进行进一步处理。比如:cattest.txt|greptest1。Jenkins中的Pi......
  • C# 一般处理程序导出excel
    步骤:1.点击前台页面Excel下载按钮。2.一般处理程序接收请求,3.调用Npoi,将DataTable数据集(也可以是别的数据集list等)填充到Excel(提前创建好的模板),另存文件(原模板不会被写......
  • LeetCode 169 Majority Element
    Givenanarraynumsofsizen,returnthemajorityelement.Themajorityelementistheelementthatappearsmorethan⌊n/2⌋times.Youmayassumethatthe......
  • shell 正则匹配
    if[["abcyyy13554221547HelloxxxWorld"=~yyy([0-9]{11})(Hello)xxx(.*)]]thenechoTheregexmatches!echo$BASH_REMATCHec......
  • Select查询
    语法:5Select 字段名1from  表名2where 字段查询条件3groupby字段/单行函数分组查询4having 根据分组依据,在进行筛选6  order......
  • Elasticsearch 字段别名 field-alias
    环境Elasticsearch8.1Kibana8.1MacOS10.14.6简介首先我们还是先了解一下,什么是字段别名?大家可能听说过索引别名,通过索引的别名可以轻松的切换所需的数据来源与哪......
  • cf C. Vertex Deletion 树形DP 删除某写节点 且保证其它节点都有至少一个相连节点的总
     https://codeforces.com/gym/103145/problem/C timelimitpertest1.5secondsmemorylimitpertest256megabytesinputstandardinputoutputstandard......
  • selenium
    importtimefromselenium.webdriver.support.waitimportWebDriverWaitfromseleniumimportwebdriverfromselenium.webdriver.common.byimportBydriver=webdriver......