自定义JSP标记 - 如何获取标记的主体? [英] Custom JSP tag - How do I get the body of the tag?

查看:109
本文介绍了自定义JSP标记 - 如何获取标记的主体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的自定义jsp标记:

I have a custom jsp tag like this:

<a:customtag>
    The body of the custom tag...
    More lines of the body...
</a:customtag>

在自定义标签中,如何获取正文的文本?

In the custom tag, how can I get the text of what the body is?

推荐答案

这很复杂,因为有两种机制。

It's complicated because there are two mechanisms.

如果你正在扩展SimpleTagSupport ,你得到 getJspBody()方法。它返回一个JspFragment,你可以调用(作家编写者)将正文内容写入作者。

If you're extending SimpleTagSupport, you get getJspBody() method. It returns a JspFragment that you can invoke(Writer writer) to have the body content written to the writer.

您应该使用SimpleTagSupport,除非您有特定的理由使用BodyTagSupport(就像遗留标记支持一样) - 更简单。

You should use SimpleTagSupport unless you have a specific reason to use BodyTagSupport (like legacy tag support) as it is - well - simpler.

如果你 使用经典标签,你可以扩展BodyTagSupport,这样就得到了访问 getBodyContent()方法。这将为您提供一个BodyContent对象,您可以从中检索正文内容。

If you are using classic tags, you extend BodyTagSupport and so get access to a getBodyContent() method. That gets you a BodyContent object that you can retrieve the body content from.

这篇关于自定义JSP标记 - 如何获取标记的主体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆