(PWC6212:应为相等符号)运行时出错



运行代码时,我得到PWC6212:等号预期错误。`

<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,我可以使标题可见,但只能显示其他标题。我希望我的问题能弄清楚,因为我真的不知道如何解释这个问题。谢谢

JSP和EL解析器只允许这些运算符。正如您所看到的,允许的关系运算符是:

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

检查某些Stirng是否与另一个Stirng不相等,如:

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

但在这种情况下,您需要检查username是否为null。所以只需使用[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>

最新更新