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
如何在JSP页面中使用JSTL标签实现if和if-else判断,判断条件使用
原文:https://www.cnblogs.com/chenhao0900/p/11800020.html