2

I am using the following code to compare two variables, but it seems it has an error as the page does not get loaded at all.

Based on this answer my code should be correct but surprisingly does not work.

If I remove the <c:when> line it shows the values of ${name} and ${myvar.employee.name}.

<c:forEach var="myvar" items="${user.names}">

    ${name}
    ${myvar.employee.name}

    <c:when test="${name eq myvar.employee.name}">
        hello
    </c:when>
Community
  • 1
  • 1
Tim Norman
  • 421
  • 1
  • 12
  • 31

2 Answers2

4

The structure with <c:when> requires <c:choose>

<c:choose>
   <c:when test="${your condition here}">
   </c:when>
   <c:otherwise>
   </c:otherwise>
</c:choose>

otherwise you will get error.

Alex
  • 11,451
  • 6
  • 37
  • 52
3

As Alex has pointed out, you cannot have non-wrapped <c:when> in your code.

But it looks like, in your case, <c:choose> is not required, because you have only a single clause. In this case <c:if> may be a better option:

<c:if test="${name eq myvar.employee.name}">
  hello
</c:if>
Community
  • 1
  • 1
Alexander Pogrebnyak
  • 44,836
  • 10
  • 105
  • 121