我想编写一个自定义JSP标记,其输出包含其他JSP标记,本身也应该进行动态评估。但显然,我的TagSupport
子类写入pageContext.getOut()
的所有内容都直接传送给客户端,无需进一步评估。如何制作使用其他JSP标签的自定义JSP标签?
我有一种感觉,这应该是非常简单的,因为它似乎是人们想要使用自定义标签的第一件事情之一:封装和重复使用其他自定义标签,避免代码重复。
如何使下面的代码做它显然想办?:
public class MyTag extends TagSupport {
public int doStartTag() throws JspException {
try {
pageContext.getOut().println(
"The output from this tag includes other tags " +
"like <mypackage:myOtherTag>this one</mypackage:myOtherTag> " +
"which should themselves be evaluated and rendered."
)
} catch (IOException e) {
throw new JspException(e);
}
return SKIP_BODY;
}
}
编辑:在我的具体使用情况的一些背景知识,如果有帮助。我有一个自定义标记<user>
,它以一种对我的应用程序有用的方式动态呈现用户名(鼠标悬停为名,姓,电话号码等)。我现在正在编写另一个标签<comment>
来显示用户评论,并且我想用我现有的<user>
标签来呈现<comment>
标签输出中的用户名。
这应有助于:http://stackoverflow.com/问题/ 2502282/custom-jsp-tag-how-do-i-get-the-body-of-the-tag –