jsp判斷List長度

來源:互聯網
上載者:User

標籤:jsp判斷list長度

大家好:

今天遇到的一個問題就是後台往前台傳List ,前台判斷List的長度!

查別人的都說要加別的標籤

<span style="font-size:14px;color:#cc0000;">jsp開發中經常要判斷list或者字串的長度來做些事情,因為jstl標籤中的if不支援else,所以選擇while來做。<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>--------這裡就需要有standard.jar這個包引入兩個標籤庫之後就能實現長度判斷了,例如Jsp代碼  收藏代碼    <c:choose>          <c:when test="${fn:length(contact.tagschosen) == 0}">          <span class="grouped">未分組</span>          </c:when>          <c:otherwise>          <c:forEach items="${contact.tagschosen}" var="tags">              <span class="grouped">${tags.tagname}</span>          </c:forEach>          </c:otherwise>      </c:choose>  </span>
而我今天要說的是只需要 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 這個標籤就好了

只需要在 body中加入個隱式標籤就可以輕輕鬆鬆判斷了

<input type="hidden" name="tcMedicineList" value="${tcMedicineList}" />

  <c:if test="${tcMedicineList.size()>2}"> 

這樣就OK了!!!

<span style="font-size:14px;"><body><input type="hidden" name="tcMedicineList" value="${tcMedicineList}" /><input type="hidden" name="weMedicineList" value="${weMedicineList}" /><input type="hidden" name="otMedicineList" value="${otMedicineList}" /><input type="hidden" name="trMedicineList" value="${trMedicineList}" /><input type="hidden" name="ptcMedicineList" value="${ptcMedicineList}" /><!--recipe start--><div class="container">    <dl class="recipe_pay_detail recipe_detail">            <dt class="medicine_head"><i class="ico ico_recipe recipe_bg6"></i>中藥藥品:</dt>                 <dd id="medicine_info_chn">                 </span><span style="font-size:18px;color:#ff6600;"> <span style="background-color: rgb(102, 0, 204);"><c:forEach items="${tcMedicineList}" var="tcMedicineList" begin="0" end="1"></span></span><span style="color: rgb(255, 102, 0);font-size:18px; font-family: Arial, Helvetica, sans-serif;"> </span><span style="color: rgb(255, 102, 0);font-size:18px; font-family: Arial, Helvetica, sans-serif;"><!-- 迴圈List只顯示前兩條 --></span>
<span style="font-size:14px;">              <p><span>${tcMedicineList.name}</span>${tcMedicineList.standard} </p>        </c:forEach>           </span><strong style="font-size:14px;">   </strong><span style="font-size:18px;">  </span><span style="color:#ff9900;"><span style="font-size:18px;"><span style="background-color: rgb(51, 102, 255);">  <c:if test="${tcMedicineList.size()!=0&&2>tcMedicineList.size()}"></span> </span><span style="font-size:14px;">  </span></span><span style="color: rgb(255, 102, 0); font-size: 18px; font-family: Arial, Helvetica, sans-serif;"><!-- 如果List條數不等於0 並且條數小於2條時 --></span><span style="font-size:14px;"><span style="color:#ff9900;"></span>          <c:forEach items="${ptcMedicineList}" var="ptcMedicineList"<span style="background-color: rgb(51, 102, 255);"><span style="color:#ff0000;"> begin="0" end="0"</span></span>>          <p>          劑量:${ptcMedicineList.num} ${ptcMedicineList.unit}<br/>   <%--       劑量:${ptcMedicineList.dosage}<br> --%>        用法:${ptcMedicineList.usemethod} ${ptcMedicineList.dosage}          </p>        </c:forEach>           </c:if>                    <c:if test="${tcMedicineList.size()>2}"> </span><span style="color: rgb(255, 102, 0); font-family: Arial, Helvetica, sans-serif; font-size: 18px;"><!-- 如果List條數大於2條時 --></span><span style="font-size:14px;">           <c:forEach items="${ptcMedicineList}" var="ptcMedicineList" <span style="background-color: rgb(51, 102, 255);"><span style="color:#ff6600;">begin="0" end="0"></span></span><span style="color:#ffff66;">></span> </span><span style="color: rgb(255, 102, 0); font-family: Arial, Helvetica, sans-serif;font-size:18px;"><!-- 迴圈List只顯示前一條 --></span><span style="font-size:14px;">          <p>      劑量:${ptcMedicineList.num} ${ptcMedicineList.unit}<br/>        用法:${ptcMedicineList.usemethod} ${ptcMedicineList.dosage}            <a href="#" class="btn btn_o_c btn_open" id="btn_open_chn">展開</a>          </p>        </c:forEach>        </c:if>               </dd>                 <dd id="medicine_detail_chn">        <c:forEach items="${tcMedicineList}" var="tcMedicineList">            <p> <span>${tcMedicineList.name}</span>${tcMedicineList.standard}</p>           </c:forEach>       <c:forEach items="${ptcMedicineList}" var="ptcMedicineList" begin="0" end="0"></span><span style="color: rgb(255, 102, 0); font-family: Arial, Helvetica, sans-serif;font-size:18px;"><!-- 迴圈List只顯示前一條 --></span><span style="font-size:14px;">          <p>      劑量:${ptcMedicineList.num} ${ptcMedicineList.unit}<br/>        用法:${ptcMedicineList.usemethod} ${ptcMedicineList.dosage}             <a href="#" class="btn btn_o_c btn_close" id="btn_close_chn">收合</a>            </p>          </c:forEach>        </dd>               <dt  class="medicine_head"><i class="ico ico_recipe recipe_bg4"></i>西藥藥品:</dt>                 <dd id="medicine_info">        <c:forEach items="${weMedicineList}" var="weMedicineList" begin="0" end="1">        <p><span>${weMedicineList.name}</span>${weMedicineList.standard}</p>       </c:forEach>       <c:if test="${weMedicineList.size()>2}">            <p>...<a href="#" class="btn btn_o_c btn_open" id="btn_open">展開</a></p>       </c:if>        </dd>                        <dd id="medicine_detail">          <c:forEach items="${weMedicineList}" var="weMedicineList">            <p><span>${weMedicineList.name}</span>${weMedicineList.standard}</p>            </c:forEach>           <p> <a href="#" class="btn btn_o_c btn_close" id="btn_close">收合</a></p>        </dd>             <%--      <dt> <i class="ico ico_recipe recipe_bg4"></i>檢查項目:</dt>         <dd id="medicine_info_check">        <c:forEach items="${entity}" var="entity" begin="0" end="1">        <p><span>${entity.name}</span></p>       </c:forEach>            <p><a href="#" class="btn btn_o_c btn_open" id="btn_open">展開</a></p>        </dd>        <dd id="medicine_detail_check">          <c:forEach items="${entity}" var="entity">            <p><span>${entity.name}</span></p>            </c:forEach>           <p> <a href="#" class="btn btn_o_c btn_close" id="btn_close">收合</a></p>        </dd>      --%>            <dt><i class="ico ico_recipe recipe_bg5"></i>其他:</dt>      <dd>      <c:forEach items="${otMedicineList}" var="otMedicineList">         <p><span>${otMedicineList.name}</span>${otMedicineList.standard}</p>      </c:forEach>      </dd>      <dt><i class="ico ico_recipe recipe_bg2"></i>治療項目:</dt>      <c:forEach items="${trMedicineList}" var="trMedicineList">      <dd><p><span>${trMedicineList.name}</span>${trMedicineList.standard}</p></dd>      </c:forEach>         <dd class="recipe_sum sum_all">合計:${fee} 元</dd>    </dl></div></span>




jsp判斷List長度

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.