2

I have a custom tag that has no body at all. I'm trying to programmatically replace the empty body with, for simplicity's sake,

[<c:out value="SUCCESS!"/>]

The goal is to see "[SUCCESS!]" displayed by the JSP which uses the tag, but all I see is "[]" and if I look at the generated source code, I can see that the c:out statement is written on the page between the brackets, but not interpreted.

Is there a common way to achieve this ? The final goal will be to use other custom tags instead of the "c:out" tag. The tags/content will come from a database. I tried different techniques with SimpleTagSupport and BodyTagSupport but none of those were successfull. In fact I'm not sure if it is technically possible to do it, since, the tag has already been interpreted at that time.. But then how should this be done ?

4

1 回答 1

1

当JSP 转换为 servlet时,服务器标签(如您的自定义标签或 JSTL 标签)会转换为 Java 代码。例如,下面的 JSP 代码:

<c:out value="FooBar" />

在 servlet 中被翻译成这样的东西:

....
OutTag outTag = (OutTag) tagHandlerPool.get(OutTag.class);
outTag.setPageContext(pageContext);
outTag.setParent(null);
outTag.setValue(new String("FooBar"));
int evalOut = outTag.doStartTag();
....

在您的自定义标记中,您可以调用其他 Java 类/方法,并且可以将 HTML 代码(不是 JSP 代码)写入响应。

没有解释,因为在这个[<c:out value="SUCCESS!"/>]级别它只是一个直接写入响应的字符串。

于 2012-04-07T19:51:08.677 回答