如何在JSP頁面中使用JSTL標簽實現if和if-else判斷,判斷條件使用


1. 首先工程中要有JSTL的兩個jar包:jstl.jar 和 standard.jar。

2. 其次在頁面中引入標簽庫:

是這個標簽!!!    網上同類文章很多有錯的標簽。

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

 

3. 只用if: <c:if> 用於實現 java 中的 if 語句功能。
<c:if test="${'<%=imgstr%>'==null}">
       Print this sentence .
</c:if>
若為 true ,會打印中間部分。也可以聲明 var ,方便下一步判斷。
<c:iftest="${'<%=imgstr%>'==null}" value=”result”/>
<c:out value=”${result}” /> 

 

4. <c:choose> 和 <c:when> 、 <c:otherwise> 一起實現互斥條件執行,類似於 java 中的 if else.
<c:choose> 一般作為 <c:when> 、 <c:otherwise> 的父標簽。
<c:choose>
                   <c:when test="${'<%=imgstr%>'==null}">
                   <img src="person/images/默認頭像.png" id="img3"/>
                   </c:when>
                   <c:otherwise>
                   <img src="<%=imgstr%>" id="img4"/>
                   </c:otherwise>

</c:choose>
————————————————
原文鏈接:https://blog.csdn.net/qq_33609401/article/details/77393102


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM