• EL表达式


    EL 表达式

    Expression Language 表达式语⾔,替代 JSP ⻚⾯中数据访问时的复杂编码,可以⾮常便捷地取出域对
    象(pageContext、request、session、application)中保存的数据,前提是⼀定要先 setAttribute
    EL 就相当于在简化 getAttribute
    ${变量名} 变量名就是 setAttribute 对应的 key 值。
     
    1、EL 对于 4 种域对象的默认查找顺序:
    pageContext -》request-〉session-》application
    按照上述的顺序进⾏查找,找到⽴即返回,在 application 中也⽆法找到,则返回 null
    <%
        pageContext.setAttribute("name","page");
        request.setAttribute("name","request");
        session.setAttribute("name","session");
        application.setAttribute("name",application);
    %>
    ${name}

    结果

    page优先级最高

    将page那行注释掉

     所以优先级为:pagecontext,request,session,application

    2、指定作⽤域进⾏查找
    pageContext:${pageScope.name}
    request:${requestScope.name}
    session:${sessionScope.name}
    application:${applicationScope.name}

    3.${}的原理:

    与方法绑定,非与属性绑定

    user.num解析

    1.找user里面的getNum方法,然后方法里面的return的值返回

    4.一个例子

    <%
     User user = new User(1,"张三",86.5,new Address(1,"⼩寨"));
     System.out.println(user.toString());
     pageContext.setAttribute("user",user);
     %>
     <table>
     <tr>
     <th>编号</th>
     <th>姓名</th>
     <th>成绩</th>
     <th>地址</th>
     </tr>
     <tr>
     <td>${user.id}</td>
     <td>${user.name}</td>
     <td>${user.score}</td>
     <td>${user.address}</td>
     </tr>
     </table>
    ${user["id"]}

    5.EL执行表达式

    && || ! < > <= <= ==
     
    &&: and
    || :or
    ! :not
    == :eq
    != :ne
    < :lt
    > :gt
    <= :le
    >= :ge
    empty 变量为 null,⻓度为0的String,size为0的集合</
    <%
        request.setAttribute("num1",true);
        request.setAttribute("num2",false);
    %>
    <hr/>
    ${name1&&num2}
    <%
        request.setAttribute("num1",true);
        request.setAttribute("num2",false);
    %>
    <hr/>
    ${name1 and num2}
    <%
        List<String> list=new ArrayList<>();
        request.setAttribute("num3",list);
    %>
    <hr/>
    ${empty num3}
  • 相关阅读:
    What is the difference between the ways to implement inheritance in javascript.
    understand dojo/domReady!
    Using dijit/Destroyable to build safe Components
    Session Tracking Approaches
    difference between forward and sendredirect
    What is the DD in java web application
    棋牌游戏-后端架构(1)
    成为技术领导者笔记--领导的MOI模型
    最小表示法
    SGI STL rope
  • 原文地址:https://www.cnblogs.com/hanabi-521/p/14320051.html
Copyright © 2020-2023  润新知