2020-08-22

ER表达式(Express Language)

  • 是一种表达式语言

  • ${requestScope.name}
    
  • 将空值可以自动归零,进行计算

注意事项

EL表达式的禁用问题

  • 不支持EL表达式的时候使用这个
isELIgnores = "false";
//忽略EL表达式

关系表达式

  \${3>2}:${3>2}<br>
    \${3==2}:${3==2}<br>
    \${3<=2}:${3<=2}<br>
    \${3!=2}:${3!=2}<br>
<hr>
    \${3 gt 2}:${3 gt 2}<br>
    \${3 eq 2}:${3 eq 2}<br>
    \${3 lt 2}:${3 lt 2}<br>
    \${3 le 2}:${3 le 2}<br>
    \${3 ne 2}:${3 ne 2}<br>

逻辑运算符

\${true && false}:${true && false}<br>
    \${true || false}:${true || false}<br>
    \${1 & 0}:${1 & 0}<br>
    \${!true}:${!true}<br>
    \${not true}:${not true}<br>
    
    
    \${false and true}:${false and true}<br>
    \${false or true}:${false or true}<br>
    \${not true}:${not true}<br>

运算符

 <%=request.getParameter("name")==null || "".equals(request.getParameter("name"))
    ?"不存在":request.getParameter("name")%>
${param.name?"不存在":param.name}
  • 两者效果一样,EL表达式更加方便

作用域对象

pageContext,request,session,application

对应中EL中对象

pageScope,requestScope,sessionScope,applicationScope

取值

<%
        pageContext.setAttribute("Key","pageValue");
        request.setAttribute("Key","requesrValue");
        session.setAttribute("Key","sessionValue");
        application.setAttribute("Key","applicationValue");
    %>
<hr>
    <%=pageContext.getAttribute("key")%>
    <%=request.getAttribute("key")%>
    <%=session.getAttribute("key")%>
    <%=application.getAttribute("key")%>
    <%=pageContext.findAttribute("key")%>
<hr>
    <h3>EL</h3>
    ${pageScope.key}<br>
    ${requestScope.key}<br>
    ${sessionScope.key}<br>
    ${applicationScope.key}<br>
    ${key}<br>
 
 <%=pageContext.findAttribute("key")%>
${key}<br>

两者等价

EL的两种写法

  • requestScope[“name”]和requestScope.name
<%
    User user = new User();
    user.setName("张三");
    user.setPassword("123");
    request.setAttribute("userx",user);
%>

    <hr>
    <p>
        用户名:<%=user.getName()%>
    </p>
    <hr>
    <p>
        EL用户名:${requestScope.userx.username}
    </p>
    <p>
        EL用户名:${requestScope["userx"]["username"]}
    </p>
<%
        request.setAttribute("u.x","王五");
%>
   	${requestScope.u.x}
    ${requestScope["u.x"]}

EL集合

<%
        String[] ss = {"AAA","BBB","CCC"};
        request.setAttribute("ss",ss);
        Map<String,Object> map = new HashMap<>();
        map.put("age",22);
        request.setAttribute("map",map);

        Set<String> set = new HashSet<>();
        set.add("xxx");
        set.add("yyy");
        request.setAttribute("set",set);
    %>
    <p>
    ${requestScope.ss[2]}
    </p>
    <p>
    ${requestScope.map.age}
    </p>
    <p>
    ${requestScope.map["age"]}
    </p>

引入链接库

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jkgzEPwi-1598108514248)(E:/computer%20software/Typora/Typora/upload/image-20200425150624259.png)]

out
  • 可以提供默认值

    • <c:out value="${pageScope.age}" default="18"></c:out>
      //默认值为18
      
  • 判断

    • <c:if></c:if>
      
  • when循环

    • <c:choose>
      	<c:when test="${score>=90}">优秀</c:when>
      </c:choose>
      
  • 循环

    • <c:forEach var="i" begin="0" end="100" varStart="st">
      <c
      </c:forEach>
      
格式化
  • 数字
  • 货币
函数
  • 求长度
  • ${fn:length(cc)}
截取
${fn:substring(cc,3,6)}
//截取cc字符串,从第三个开始第六个结束

作用域

作用域范围

page,request,session,application

作用域对象

pageContext,request,session,application

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值