• JSTL--表达式操作


    核心标签库:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

    1.输入输出操作

    c:out 可以对特殊字符进行自动转义

    <%
      request.setAttribute("book", "<<Java in web>>");
    %>
    <!-- output(in IE):book:<> -->
    book:${requestScope.book }
    <br/>
    <!-- output:book:<<Java in web>> -->
    book:<c:out value="${requestScope.book}"></c:out>

    c:set 可以为域赋属性值,其中 value 属性支持 EL 表达式;还可以为域对象中的 JavaBean 的属性赋值,target、value都支持 EL 表达式。

    c:set可用的属性有:var、scope、value、target、property。

    <%
      Customer cust = new Customer();
      cust.setId("-900");
      request.setAttribute("cust", cust);
    %>
    <c:set var="newId" scope="request" value="2345"></c:set>
    ${requestScope.cust.id}
    newId: ${requestScope.newId }
    <c:set target="${requestScope.cust }" property="id" value="${requestScope.newId}"></c:set>
    ${requestScope.cust.id}

    c:remove 移除指定域对象的指定属性值

    <c:remove var="newId" scope="request"/>

    2.流程控制

    c:if 没有else,不能实现if...else if...else逻辑,但可以保存当前的判断条件的结果(true或false)。

    <c:if test="${param.age > 18 }" var="isAdult" scope="request">
    成年了!
    </c:if>
    <br/>
    ${requestScope.isAdult }

    c:choose c:choose, c:when, c:otherwise: 可以实现 if...else if...else if...else 的效果. 但较为麻烦。其中: c:choose 以 c:when, c:otherwise 的父标签出现。

    c:when, c:otherwise 不能脱离 c:choose 单独使用。c:otherwise 必须在 c:when 之后使用。 

    <c:choose> 
      <c:when test="${param.age > 60 }">
        老年
      </c:when>
      <c:when test="${param.age > 35 }">
        中年
      </c:when>
      <c:when test="${param.age > 18 }">
        青年
      </c:when>
      <c:otherwise>
        未成年. 
      </c:otherwise>
    </c:choose>
  • 相关阅读:
    Hdu 3564 Another LIS 线段树+LIS
    利用ESLINT进行js 语法检查,以及局部安装时遇到的一些坑
    操作系统杂谈
    算法杂谈
    前端杂谈
    操作系统复习
    vue之——从彩笔的进步之路
    一丢丢学习之webpack4 + Vue单文件组件的应用
    计蒜客 2017复赛 百度地图导航
    electron打包之真的恶心
  • 原文地址:https://www.cnblogs.com/itfky/p/13728237.html
Copyright © 2020-2023  润新知