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