1

我的 jsp 中有以下代码:

<% pageContext.setAttribute("warnings",Globals.WARNING_MESSAGES); %>
<c:choose>
    <c:when test="${requestScope[pageScope.warnings] or sessionScope[pageScope.warnings]}">
        <html:errors header="warnings.header" footer="warnings.footer" prefix="warnings.prefix" suffix="warnings.suffix"/>
        <c:remove var="${pageScope.warnings}" scope="session"/>
    </c:when>
    <c:otherwise>
        <html:errors/>
    </c:otherwise>
</c:choose>

我想知道是否有任何方法(无需深入研究源代码)知道某个属性是否可用于 EL 编码。

在这段代码中,我想使用一个脚本变量定义为我在 pageScope 容器中设置的常量。当我从引用脚本变量的 sessionScope 中删除变量时,我想使用相同的机制,但似乎该<c:remove var>属性拒绝解释我的脚本变量,这破坏了引用我的常量声明的所有努力。我可以使用 jsp scriptlet 来解决这个问题,但是有没有“更好”的方法来解决这个问题?

4

1 回答 1

1

我不确定我是否理解您的问题,但我认为您正在寻找 EL 的“空”运算符来测试属性是否存在:

<c:if test="${empty pageScope.warnings}">
//做一点事
</c:如果>

如果 pageScope.warnings 未定义(null),这将返回 true。

于 2008-10-04T05:51:27.307 回答