1

I have implemented the if / else tag in JSTL like following. But its not working. If condition not checking.

<c:choose>
    <core:if ${capital.nextCapital()} eq ${request.capital}>
         <p> Yes. The capital of ${capital.nextState()} is ${capital.nextCapital()} </p>
     </core:if>
    <c:otherwise>
         <p>No. The capital of ${capital.nextState()} is ${capital.nextCapital()} </p>
    </c:otherwise>
</c:choose>

1 Answer 1

1

That is not valid syntax at all.

  1. the standard prefix is c, not core
  2. inside c:choose, you can use c:when and c:otherwise. Not c:if.
  3. the boolean condition must be inside a test attribute:
  4. Attributes must be surrounded by quotes:

    <c:when test="...">
    
  5. The whole boolean EL expression must be inside ${}:

    <c:when test="${ ... }">
    

So the end result should be

<c:when test="${capital.nextCapital() eq request.capital}"> ... </c:when>

I suggest you re-read your book or tutorial about custom tags and the JSTL.

Sign up to request clarification or add additional context in comments.

1 Comment

You need to refine your diagnostic. "not working" doesn't mean anything concrete. What happens? What is printed if you add ${capital.nextCapital()} to know what its value is? And when you add ${request.capital}?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.