JSP - 我可以使用里面?例外:“必须使用 jsp:body 来指定标记主体”

发布于 2024-09-14 18:45:52 字数 767 浏览 2 评论 0原文

我在 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 &lt;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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春花秋月 2024-09-21 18:45:52

元素的主体隐式定义为相应元素的主体。主体还可以使用显式表示。如果一个或多个是必需的,则这是必需的。元素出现在标签的主体中。查看 元素属性正文

但这不是真正的问题。问题是不能很好地与条件标签配合使用。正在尝试在其父标记上设置属性,在您的示例中为

您可以使用;在元素内部(正如 BalusC 在他的评论中建议的那样),但这将导致属性具有空值,或者您可以从:

<jsp:element ...>
  <c:if test="${true}">
    <jsp:attribute name="extraInlineComplianceJavascript">
      ....
    </jsp:attribute>
  </c:if>
</jsp:element>

到(更详细):

<c:if test="${true}">
  <jsp:element ...>
    <jsp:attribute name="extraInlineComplianceJavascript">
      ....
    </jsp:attribute>
  </jsp:element>
</c:if>
<c:if test="${false}">
  <jsp:element ...>
     <!-- no attribute for false -->
  </jsp:element>
</c:if>

您也可以使用。当然,它不能与多个属性一起很好地工作: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:

<jsp:element ...>
  <c:if test="${true}">
    <jsp:attribute name="extraInlineComplianceJavascript">
      ....
    </jsp:attribute>
  </c:if>
</jsp:element>

to (a more verbose):

<c:if test="${true}">
  <jsp:element ...>
    <jsp:attribute name="extraInlineComplianceJavascript">
      ....
    </jsp:attribute>
  </jsp:element>
</c:if>
<c:if test="${false}">
  <jsp:element ...>
     <!-- no attribute for false -->
  </jsp:element>
</c:if>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文