java 不理解 JspTagException:“非法使用 <when>-style 标签而没有 <choose> 作为其直接父级
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3652502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Don't understand JspTagException: "Illegal use of <when>-style tag without <choose> as its direct parent
提问by Egg Yolk
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
:
我已经盯着下面嵌套的标签看了大约一个小时,但我仍然不明白为什么我一直收到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?
不允许在 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>
回答by Asaph
You have <c:otherwise>
tags nested inside<c:when>
tags. These 2 tags need to be peer to each other. Try this:
您有<c:otherwise>
嵌套在<c:when>
标签内的标签。这 2 个标签需要相互对等。试试这个:
<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.
顺便说一句:您的alt
每个<img>
标签中都列出了两次属性。我在答案中删除了多余的。
回答by axtavt
You have <c:otherwise>
inside <c:when>
. <c:otherwise>
should be used as follows:
你有<c:otherwise>
里面<c:when>
。<c:otherwise>
应如下使用:
<c:choose>
<c:when ... >
1st alternative
</c:when>
<c:when ... >
2nd alternative
</c:when>
...
<c:otherwise>
otherwise
</c:otherwise>
</c:choose>