JSTL中只有<c:if>没有else,如果打算实现如下逻辑:
Random rd = new Random();
int i = rd.nextInt(3);
if (i == 0) {
System.out.println(i);
} else if (i == 1) {
System.out.println(i);
} else {
System.out.println(i);
}
可以直接用<c:if>来操作,另外一种可以采用 <c:choose> <c:when><c:otherwise>来替换,具体实现如下:
<c:choose>
<c:when test="${i==0}">
<c:out value="i" />
</c:when>
<c:when test="${i==1}">
<c:out value="i" />
</c:when>
<c:otherwise>
<c:out value="i" />
</c:otherwise>
</c:choose>