- <</span>c:if>没有<</span>c:else>可以用<</span>c:choose>来取代结构:
- <</span>c:choose>
-
-
<</span>c:when test=""> 如果 -
</</span>c:when> -
-
<</span>c:otherwise> 否则 -
</</span>c:otherwise> - </</span>c:choose>
-
- 在同一个
<</span>c:choose> 中,当所有 <</span>c:when> 的条件都没有成立时,则执行 <</span>c:otherwise> 的本体内容。 -
- 语法
-
- <</span>c:otherwise>
-
- 本体内容
-
- </</span>c:otherwise>
-
- 属性
-
- 无
-
- 限制
-
- ·<</span>c:otherwise>
必须在 <</span>c:choose> 和 </</span>c:choose>之间 -
- ·在同一个
<</span>c:choose> 中时,<</span>c:otherwise> 必须为最后一个标签 -
- 说明
-
- 在同一个
<</span>c:choose> 中,假若所有 <</span>c:when> 的test属性都不为true时,则执行 <</span>c:otherwise> 的本体内容。 -
- 范例
-
- 笔者举一个典型的
<</span>c:choose>、<</span>c:when>和<</span>c:otherwise>范例: -
- <</span>c:choose>
-
- <</span>c:when
test="${condition1}"> -
- condition1为true
-
- </</span>c:when>
-
- <</span>c:when
test="${ condition2}"> -
- condition2为true
-
- </</span>c:when>
-
- <</span>c:otherwise>
-
- condition1和condition2都为false
-
- </</span>c:otherwise>
-
- </</span>c:choose>
-
- 范例说明:当condition1为true时,会显示“condition1为true”;当condition1为false且 condition2为true时,会显示“condition2为true”,如果两者都为false,则会显示“condition1和 condition2都为false”。
-
- 注意
-
- 假若condition1和condition2两者都为true时,此时只会显示"condition1为true",这是因为在同一个<</span>c:choose>下,当有好几个<</span>c:when>都符合条件时,只能有一个<</span>c:when>成立。
关于<c:if>没有<c:else>解决方案
最新推荐文章于 2021-02-25 17:13:29 发布