I've been staring at the tag nesting below for about an hour now and I still can't figure out why I keep getting a JspTagException
:
"Illegal use of <when>-style tag without <choose> as its direct parent"
Are you not allowed to nest condition tags this deeply in JSTL?
<c:choose>
<c:when test="${rec.image1Available}">
<img alt="altname" src="/img1.jpg" alt="altname" />
<c:otherwise>
<c:choose>
<c:when test="${rec.image2Available}">
<img alt="altname" src="/img2.jpg" alt="altname" />
<c:otherwise>
<c:choose>
<c:when test="${rec.image3Available}">
<img alt="altname" src="img3.jpg" alt="altname" />
<c:otherwise>
<img alt="altname" src="/holder.jpg" alt="altname" />
</c:otherwise>
</c:when>
</c:choose>
</c:otherwise>
</c:when>
</c:choose>
</c:otherwise>
</c:when>
</c:choose>
You have <c:otherwise>
inside <c:when>
. <c:otherwise>
should be used as follows:
<c:choose>
<c:when ... >
1st alternative
</c:when>
<c:when ... >
2nd alternative
</c:when>
...
<c:otherwise>
otherwise
</c:otherwise>
</c:choose>
You have <c:otherwise>
tags nested inside <c:when>
tags. These 2 tags need to be peer to each other. Try this:
<c:choose>
<c:when test="${rec.image1Available}">
<img src="/img1.jpg" alt="altname" />
</c:when>
<c:otherwise>
<c:choose>
<c:when test="${rec.image2Available}">
<img src="/img2.jpg" alt="altname" />
</c:when>
<c:otherwise>
<c:choose>
<c:when test="${rec.image3Available}">
<img src="img3.jpg" alt="altname" />
</c:when>
<c:otherwise>
<img src="/holder.jpg" alt="altname" />
</c:otherwise>
</c:choose>
</c:otherwise>
</c:choose>
</c:otherwise>
</c:choose>
BTW: You have alt
attributes listed twice in each of your <img>
tags. I removed the extra ones in my answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With