jstl 的<c:if>标签没有else的解决办法
2013-06-19 10:59
495 查看
我们可以采用<c:choose>来代替<c:if>
具体结构:
<c:choose>
<c:when test=""> 如果
</c:when>
<c:otherwise> 否则
</c:otherwise>
</c:choose>
代码示例:
<c:choose>
<c:when test="${sessionScope.USERTYPE == 'inner'}">
<c:set value="${context_root}/igmgr/MEB004.dow" var="action" scope="page"/>
</c:when>
<c:when test="${sessionScope.USERTYPE == 'merc'}">
<c:set value="${context_root}/igmgr/MEB021.dow" var="action" scope="page"/>
</c:when>
<c:otherwise>
<c:set value="${context_root}/igmgr/MEB020.dow" var="action" scope="page"/>
</c:otherwise>
</c:choose>
范例说明:当condition1为true时,会显示“condition1为true”;当condition1为false且condition2为true时,会显示“condition2为true”,如果两者都为false,则会显示“condition1和condition2都为false”。
注意:假若condition1和condition2两者都为true时,此时只会显示"condition1为true",这是因为在同一个<c:choose>下,当有好几个<c:when>都符合条件时,只能有一个<c:when>成立。
具体结构:
<c:choose>
<c:when test=""> 如果
</c:when>
<c:otherwise> 否则
</c:otherwise>
</c:choose>
代码示例:
<c:choose>
<c:when test="${sessionScope.USERTYPE == 'inner'}">
<c:set value="${context_root}/igmgr/MEB004.dow" var="action" scope="page"/>
</c:when>
<c:when test="${sessionScope.USERTYPE == 'merc'}">
<c:set value="${context_root}/igmgr/MEB021.dow" var="action" scope="page"/>
</c:when>
<c:otherwise>
<c:set value="${context_root}/igmgr/MEB020.dow" var="action" scope="page"/>
</c:otherwise>
</c:choose>
范例说明:当condition1为true时,会显示“condition1为true”;当condition1为false且condition2为true时,会显示“condition2为true”,如果两者都为false,则会显示“condition1和condition2都为false”。
注意:假若condition1和condition2两者都为true时,此时只会显示"condition1为true",这是因为在同一个<c:choose>下,当有好几个<c:when>都符合条件时,只能有一个<c:when>成立。
相关文章推荐
- jstl 的<c:if>标签没有else的解决办法
- JSTL 的<c:if>标签没有else的解决办法
- 【JSTL】<c:if test=“”>没有else的解决方法
- <c:if>没有<c:else>解决办法
- IE6下z-index层以及绝对定位的PNG背景透明层中<a>标签链接失效的解决办法
- <c:if>没有<c:else>解决办法
- JSTL标签用法:<c:choose><c:forEach><c:if><...
- jstl 的if else <c:choose><c:when test="">如果</c:when><c:otherwise>否则</c:otherwise></c:choose>
- 关于<:if>没有<c:else>解决方案
- 关于<c:if>没有<c:else>解决方案
- Jstl标签<c:if>的用法
- 点击<a>标签,禁止页面自动跳到顶部的解决办法
- 关于SpringMVC中找不到<mvc:resources/>标签的解决办法
- JSTL <c:if >标签的使用
- Groovy笔记-Grails g标签之<g:message>,<g:if>,<g:else>,<g:select>实例一枚
- struts2标签:<s:if><s:else>实现选择输出
- 关于SpringMVC中找不到<mvc:resources/>标签的解决办法
- Jstl标签<c:if>的用法
- 关于<c:if>没有<c:else>解决方案
- 如何在JSP页面中使用JSTL标签实现if和if-else判断,判断条件使用<%=value%>