JSTL ConditionalTagSupport与' else'功能

时间:2014-04-24 13:21:52

标签: jsp jstl jsp-tags custom-tags conditionaltagsupport

我创建了一个条件标签,如果文件不存在则返回false;如果文件存在则返回true,并且函数将文件内容设置为var。参见:

<hc:portalFile file="css/style.css" var="css" >
  <style type="text/css">
    ${css}
  </style>
</hc:portalFile>

现在我想在文件不存在时打印其他东西。所以当类中的condition函数返回false时。我需要创建像<c:choose><c:when></c:when><c:otherwise></c:otherwise></c:choose>这样的东西吗?或者我在这里完全错过了什么。

1 个答案:

答案 0 :(得分:0)

你是对的,如果你有多个条件,如果你可以使用jstl选择,何时和否则标签:

    <c:choose>
        <c:when test="${condition1}">
            <!--Display what you want for condition1-->
        </c:when>
        <c:when test="${condition2}">
            <!--Display what you want for condition1-->
        </c:when>
        <c:otherwise>
            <!--Display what you want if none of the conditions are met-->
        </c:otherwise>
    </c:choose>

此处仅显示一个条件结果,即 1)如果满足条件1,它将跳过条件2,否则。 2)如果condition1失败,则条件2通过显示并跳过opoptwise。 3)如果条件1和条件2被另外显示则显示。