(PWC6212:预期等号)错误时 运行

(PWC6212: equal symbol expected) error when running

当我 运行 我的代码时,我得到 PWC6212: equal symbol expected error。 `

    <c:set set var="un" value="${username}"/>
    <c:choose>
        <c:when test="${!un.equals(null)}">

            <div class="header">
                <img src="../src/img/cd2.png">
                <div class="header-right">
                    <a href="../learning-material.html">View Material</a>
                    <a href="../SummativeQuestionHome.html">Summative</a>
                    <a href="../">Formative</a>
                    <a href="../View-Performance.html">View Performance</a>
                    <a href="../">Manage Profile</a>
                    <a class="active" href="logoutServlet">Logout</a>
                </div>
            </div>

        </c:when>
        <c:otherwise>

            <div class="header">
                <img src="../src/img/cd2.png">
                <div class="header-right">
                   <a class="active" href="logoutServlet">Logout</a>
                    <a class="active" href="../loginpage.jsp">Login</a>
                </div>
            </div>
        </c:otherwise>
    </c:choose>

`有办法解决这个问题吗?如果我删除顶部的 @taglib,我可以使 header 可见,但只有其他可见。我希望我的问题在某种程度上是清楚的,因为我真的不知道如何解释这个问题。谢谢

JSP 和 EL 解析器只允许 these 运算符。如您所见,允许的关系运算符是:

==, eq, !=, ne, <, lt, >, gt, <=, ge, >=, le

检查一些 Stirng 是否不等于另一个像:

<c:choose>
    <c:when test="${un ne 'other string'}">
        <%-- NOT equals --%>
    </c:when>
    <c:otherwise>
        <%-- Otherwise (equals) --%>
    </c:otherwise>
</c:choose>

但在这种情况下,您要检查 username 是否为空。 所以只需使用 [not] empty 条件,如:

<c:choose>
    <c:when test="${un not empty}">
        <%-- not empty or null --%>
    </c:when>
    <c:otherwise>
        <%-- empty or null  --%>
    </c:otherwise>
</c:choose>