如何从传统 JSP 自定义标记调用 JSP 2.0 *.tag 文件?

发布于 2024-08-20 23:01:46 字数 93 浏览 3 评论 0原文

我已经编写了一个 JSP 自定义标记,在扩展 TagSupport 的类中实现,并且我想调用另一个编写为 *.tag 文件的自定义标记。这可能吗?如果可以的话,该怎么办呢?

I have written a JSP custom tag, implemented in a class that extends TagSupport, and I'd like to invoke another custom tag that was written as a *.tag file. Is this possible? If so, how can it be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

殤城〤 2024-08-27 23:01:46

不能,标记文件只能从 JSP 执行。

即使从另一个标记类执行一个标记类也是有问题的,您也不应该这样做(尽管它可能会起作用)。

如果您需要从标签类调用可重用的逻辑,那么您要么需要将其提取到公共类中,要么需要将自定义标签放入 BodyTag 中,并将 .标签文件作为其中的嵌套内容,例如,如果 tagX 是一个 taglib,而 tagY 是一个标签文件,则:

<mylib:tagX>
   <mytags:tagY/>
</mylib:tagX>

然后将通过 BodyTag 接口暴露给 tagX 代码。

You can't, tag files can only be executed from a JSP.

Even executing one tag class from another is questionable, you're not supposed to do that either (although it would probably work).

If you need reusable logic that gets invoked from your tag class, then you either need to extract it out into a common class, or else you need to make your custom tag into a BodyTag, and put the .tag file in as nested content withoin it, e.g. if tagX is a taglib, and tagY is a tag file, then:

<mylib:tagX>
   <mytags:tagY/>
</mylib:tagX>

The output content of <mytags:tagY/> would then be exposed to the tagX code via the BodyTag interface.

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