JSP - 我可以使用在里面?例外:“必须使用 jsp:body 来指定标记主体”
我在 JSP 中有以下内容:
<c:if test="${true}">
<jsp:attribute name="extraInlineComplianceJavascript">
window.isSummaryComplianceLinkVisible = '${TabList.isSummaryComplianceLinkVisible}';
window.isDetailComplianceLinkVisible = '${TabList.isDetailComplianceLinkVisible}';
window.complianceSummaryReportTag = '${helper.complianceSummaryReportTag}';
window.complianceDetailReportTag = '${helper.complianceReportTag}';
</jsp:attribute>
</c:if>
按原样,出现以下异常:
Must use jsp:body to specify tag body for <MyTag if jsp:attribute is used.
如果删除最外面的
标记,它就会起作用。在
内使用
是否存在问题?任何帮助将不胜感激。谢谢。
I have the following inside a JSP:
<c:if test="${true}">
<jsp:attribute name="extraInlineComplianceJavascript">
window.isSummaryComplianceLinkVisible = '${TabList.isSummaryComplianceLinkVisible}';
window.isDetailComplianceLinkVisible = '${TabList.isDetailComplianceLinkVisible}';
window.complianceSummaryReportTag = '${helper.complianceSummaryReportTag}';
window.complianceDetailReportTag = '${helper.complianceReportTag}';
</jsp:attribute>
</c:if>
As is, I get the following exception:
Must use jsp:body to specify tag body for <MyTag if jsp:attribute is used.
If I remove the outermost <c:if>
tags, it works. Is there a problem with using <jsp:attribute>
inside a <c:if>
? Any help would be appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
元素的主体隐式定义为相应元素的主体。主体还可以使用显式表示。如果一个或多个是必需的,则这是必需的。元素出现在标签的主体中。查看 元素、属性 和 正文。
但这不是真正的问题。问题是不能很好地与条件标签配合使用。正在尝试在其父标记上设置属性,在您的示例中为。
您可以使用;在元素内部(正如 BalusC 在他的评论中建议的那样),但这将导致属性具有空值,或者您可以从:
到(更详细):
您也可以使用。当然,它不能与多个属性一起很好地工作:D。
我个人的建议是扔掉并找到另一种方法来有条件地设置你的属性。
The body of an element is defined implicitly as the body of the the respective element. The body can also be represented explicitly using <jsp:body>. This is required if one or more <jsp:attribute> elements appear in the body of the tag. Checkout the references for element, attribute and body.
But that is not the real problem. The problem is <jsp:attribute> does not play well with conditional tags. The <jsp:attribute> is trying to set the attribute on its parent tag, which in your example is <c:if>.
You could use <c:if> inside the element (as BalusC suggested in his comment), but that will result in a an attribute with an empty value, or you could go from:
to (a more verbose):
You could also use a <c:choose>. And of course it won't work well with more than one attribute :D.
My personal suggestion would be to throw away the <jsp:attribute> and find another way to conditionally set your attributes.