JSTL中是否有if-else标签?
#1楼
除了skaffman答案外,简单的if-else也可以像这样使用三元运算符
<c:set value="34" var="num"/>
<c:out value="${num % 2 eq 0 ? 'even': 'odd'}"/>
#2楼
没有if-else,只有。
<c:if test="${user.age ge 40}">
You are over the hill.
</c:if>
您可以选择在以下情况下使用choose-when:
<c:choose>
<c:when test="${a boolean expr}">
do something
</c:when>
<c:when test="${another boolean expr}">
do something else
</c:when>
<c:otherwise>
do this when nothing else is true
</c:otherwise>
</c:choose>
#3楼
我只使用了两个if标签,以为我会添加一个答案,以防其他人使用它:
<c:if test="${condition}">
...
</c:if>
<c:if test="${!condition}">
...
</c:if>
虽然技术上不是if-else
本身的行为是相同的,避免使用的笨重的方式choose
标签,所以要根据您的要求有多复杂,这可能是可取的。
#4楼
是的,但是笨拙,例如
<c:choose>
<c:when test="${condition1}">
...
</c:when>
<c:when test="${condition2}">
...
</c:when>
<c:otherwise>
...
</c:otherwise>
</c:choose>
#5楼
您必须使用以下代码:
与<%@ taglib prefix="c" uri="http://www.springframework.org/tags/form"%>
和
<c:select>
<option value="RCV"
${records[0].getDirection() == 'RCV' ? 'selected="true"' : ''}>
<spring:message code="dropdown.Incoming" text="dropdown.Incoming" />
</option>
<option value="SND"
${records[0].getDirection() == 'SND'? 'selected="true"' : ''}>
<spring:message code="dropdown.Outgoing" text="dropdown.Outgoing" />
</option>
</c:select>
来源:oschina
链接:https://my.oschina.net/u/3797416/blog/3196679