JspFragment.invoke到底做了什么?

时间:2011-12-30 15:50:04

标签: java jsp

标题中的所有内容。文档不清楚此调用的后果。

我的特殊情况是调用此方法时在参数中传递null,并且之前和之后都有代码。我没有达到这个电话的目的......
请注意,上下文是一个扩展SimpleTagSupport的类(我正在做taglib的东西)。

感谢任何指针。这是javadoc:

调用

public abstract void invoke(java.io.Writer out)
                     throws JspException,
                            java.io.IOException

    Executes the fragment and directs all output to the given Writer, or the JspWriter returned by the getOut() method of the JspContext associated with the fragment if out is null.

    Parameters:
        out - The Writer to output the fragment to, or null if output should be sent to JspContext.getOut(). 
    Throws:
        JspException - Thrown if an error occured while invoking this fragment. 
        SkipPageException - Thrown if the page that (either directly or indirectly) invoked the tag handler that invoked this fragment is to cease evaluation. The container must throw this exception if a Classic Tag Handler returned Tag.SKIP_PAGE or if a Simple Tag Handler threw SkipPageException. 
        java.io.IOException - If there was an error writing to the stream.

1 个答案:

答案 0 :(得分:1)

好吧,它允许标记接收标记想要执行的JSP片段(标记的主体)。例如,您可以设计一个if标记,该标记接收条件参数,并具有标记正文。如果条件为false,则标记不执行任何操作。如果是,则标签调用片段。 loop标记可以调用其片段(执行其体内的JSP代码),与其iterationCount参数要求的次数相同。

由于片段可能用于生成一些HTML代码以包含在响应中,因此该方法的out参数是生成片段输出的位置。例如,如果要对片段生成的内容进行后处理,而不是让片段直接写入JSP编写器,则可能需要传递另一个编写器。