Issue
I get PWC6212: equal symbol expected error when I run my code. `
<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>
`Is there a way to fix this. If I remove the @taglib on top, I could make the header visible but only the otherwise one. I wish my question somehow is clear as I dont really know how to explain this problem. Thank you
Solution
JSP and EL parser allows only these operators. As you can see allowed relational operators are:
==, eq, !=, ne, <, lt, >, gt, <=, ge, >=, le
To check if some Stirng is not equal to another like:
<c:choose>
<c:when test="${un ne 'other string'}">
<%-- NOT equals --%>
</c:when>
<c:otherwise>
<%-- Otherwise (equals) --%>
</c:otherwise>
</c:choose>
But in this case you want to check username
is null or not.
So just use [not] empty
condition like:
<c:choose>
<c:when test="${un not empty}">
<%-- not empty or null --%>
</c:when>
<c:otherwise>
<%-- empty or null --%>
</c:otherwise>
</c:choose>
Answered By - zforgo
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)