zoukankan      html  css  js  c++  java
  • EL表达式用法-查询

    导包jar:jstl.jar    standard.jar

    jsp脚本:

    <%=request.getAttribute(name)%>
    EL表达式替代上面的脚本:${requestScope.name}

    使用EL最主要的作用是获得四大域中的数据,格式

    ${EL表达式}

    此表达式主要终于代替,

    findAttribute(String name)

    取值顺序相同
    ---同样是依次从pageContext域,request域,session域,application域中

    --引入头文件

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

    <!-- 取值 -->

    ${name}

    <!-- 对象取值 对象.属性名 -->

    ${user.id}.....${user.username}.....${user.pwd}

    <!-- 集合取值Key[0].属性名  -->

    ${List[0].id}

    <!-- 项目名 -->

    ${pageContext.request.contextPath}

    <!-- el执行表达式 -->

    ${50*900000}
    ${empty user } 
    ${user==null?"空的":user.username }

    <!-- 取map集合 循环增强 -->

    <c:forEach items="${map }" var= "entry">
       ${entry.key }....${entry.value.username }
    </c:forEach>

    <!--非增强循环-->

    <c:forEach begin="1" end="3" step="1" var= "entry"> 
      ${entry}
    </c:forEach>
    var:设置变量名,并从集合中取出一组数据。相当于上面的s
    begin:指定循环的起始位置,如果没有指定,则默认从第一个值开始遍历
    end:指定循环的终止位置,如果没有指定,则默认循环到最后一个
    step:用于指定循环的步长,例如step=“2”,则会隔一个循环。下面会有例子说明
    varStatus:用于指定循环的状态,有一下四个属性值,这个也比较常用,特别是index属性值,表示索引值。
      |current:当前这次迭代的(集合中的)项
       index:当前这次迭代从 0 开始的迭代计数
       count:当前这次迭代从 1 开始的迭代计数
       first:用来表明当前这轮迭代是否为第一次迭代的标志,返回true/false
       last:用来表明当前这轮迭代是否为最后一次迭代的标志,返回true/false示例

    示例:

    <%String[] str={"1","2","3","4","5","6","7"};request.setAttribute("str",str);%>
    <c:forEach items="${str}" var="s" begin="1" end="5">
         <c:out value="${s}"></c:out><br>
    </c:forEach>
    <%String[] str={"1","2","3","4","5","6","7"}; 
    request.setAttribute(
    "str",str);%> <c:forEach items="${str}" var="s" begin="1" end="5" step="2"> <c:out value="${s}"></c:out><br> </c:forEach>
    <%String[] str={"1","2","3","4","5","6","7"}; 
    request.setAttribute(
    "str",str);%><c:forEach items="${str}" var="s" begin="1" end="5" step="2" varStatus="status">   <c:out value="index属性:${status.index}"></c:out>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   <c:out value="count属性:${status.count}"></c:out>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   <c:out value="first属性:${status.first }"></c:out>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   <c:out value="last属性:${status.last }"></c:out><br></c:forEach>

    <!--使用if判断-->
        <c:if test="${count==10}">
            aaa
        </c:if>

  • 相关阅读:
    牛客练习赛51 D题
    Educational Codeforces Round 72 (Rated for Div. 2) C题
    Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) C题
    Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) A题
    Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) A题
    Educational Codeforces Round 72 (Rated for Div. 2) B题
    Educational Codeforces Round 72 (Rated for Div. 2) A题
    《DSP using MATLAB》Problem 7.2
    《DSP using MATLAB》Problem 7.1
    《DSP using MATLAB》Problem 6.24
  • 原文地址:https://www.cnblogs.com/xiaozhang666/p/10678883.html
Copyright © 2011-2022 走看看