EL_运算符与EL_获取域中存储的值

EL_运算符

   1.使用:

        1.运算  

          运算符:

            1.算数运算符:+ - * /(div) %(mod)

            2.比较运算符:> < >= <=  == !=

            3.逻辑运算符:&&(and)  ||(or)!(not) 

            4.空运算符:empty   

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

                ${empty  list}

<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java"   %>
<html>
<head>
    <title>Title</title>
</head>
<body>


    ${3 > 4}

    \${3 > 4}
<hr>

    <h3>算数运算符</h3>
    ${3 + 4}<br>
    ${3 / 4}<br>
    ${3 div 4}<br>
    ${3 % 4}<br>
    ${3 mod 4}<br>
    <h3>比较运算符</h3>
    ${3 == 4}<br>

    <h3>逻辑运算符</h3>
    ${3 > 4  && 3 < 4}<br>
    ${3 > 4  and 3 < 4}<br>


    <h4>empty运算符</h4>
<%

    String str = "";
    request.setAttribute("str",str);

    List list = new ArrayList();
    request.setAttribute("list",list);

%>
    ${not empty str}

    ${not empty list}
</body>
</html>

 

        

 

 

EL_获取域中存储的值

      

2. 获取值
          1. el表达式只能从域对象中获取值
              2. 语法:
                1. ${域名称.键名}:从指定域中获取指定键的值
                         域名称:
                    1. pageScope --> pageContext
                    2. requestScope --> request
                    3. sessionScope --> session
                    4. applicationScope --> application(ServletContext)
                   举例:在request域中存储了name=张三
                   获取:${requestScope.name}

          2. ${键名}:表示依次从最小的域中查找是否有该键对应的值,直到找到为止。

 



         

<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>el获取域中的数据</title>
</head>
<body>


    <%
        //在域中存储数据
        session.setAttribute("name","李四");

        request.setAttribute("name","张三");
        session.setAttribute("age","23");

        request.setAttribute("str","");

    %>

<h3>el获取值</h3>
${requestScope.name}
${sessionScope.age}
${sessionScope.haha}

${name}
${sessionScope.name}




</body>
</html>

 

        

posted @ 2023-02-11 16:15  zj勇敢飞,xx永相随  阅读(19)  评论(0编辑  收藏  举报