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

サーバー タグ (カスタム タグや JSTL タグなど)は、JSP がサーブレットに変換されるときに Java コードに変換されます。たとえば、次の JSP コードは次のとおりです。

<c:out value="FooBar" />

サーブレット内で次のように変換されます。

....
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 に答える