EL表达式

Posted claduxyz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了EL表达式相关的知识,希望对你有一定的参考价值。

EL

获取page、request、session、application对象中的数据

  • 语法:${}
  • 读取顺序:page>request>session>application
    <%
        pageContext.setAttribute("name","page");
        request.setAttribute("name","request");
        session.setAttribute("name","session");
        application.setAttribute("name","application");
    %>
    ${name} ---结果为page
  • 特殊读取:${xxxScope.xxx}
    ${requestScope.name}
    ${pageScope.name}
    ${sessionScope.name}
    ${applicationScope.name}
  • 使用注意:只能使用在jsp页面
  • 及联获取:可获取对象的属性,但必须要有get方法,${user.xxxx}或者${user["xxxx"]}
    <%
        User user = new User("1","claudxyz",20);

        pageContext.setAttribute("user",user);
    %>

    ${user}

    <table border="1">
        <tr>
            <th>用户号</th>
            <th>姓名</th>
            <th>年龄</th>
        </tr>
        <tr>
            <td>${user.id}</td>
            <td>${user.name}</td>
            <td>${user.age}</td>
        </tr>
    </table>
  • EL执行表达式
    && || ! != == < > <= >=
&& and
|| or
! not
== eq
!= ne
< lt
> gt
<= le
>= ge
empty

以上是关于EL表达式的主要内容,如果未能解决你的问题,请参考以下文章

jsp--EL表达式

jsp中的EL表达式

Jsp入门EL表达式_学习笔记

第五条知识点

EL表达式

EL表达式的基本知识