JspFragment.invoke究竟做了什么?

问题描述:

几乎所有的标题。文件不清楚这个电话的后果。JspFragment.invoke究竟做了什么?

我的具体情况是,这个方法是用空传入参数调用的,前后有代码。我没有得到这个调用的目的...
请注意,上下文是一个扩展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. 

那么,它允许标签接收JSP片段(标记的机构)当标签要执行。例如,您可以设计一个if标签,它接收一个条件参数,并且具有一个标签主体。如果条件为false,则标签不会执行任何操作。如果这是真的,标签调用片段。一个loop标签可以调用它的片段(执行其正文中的JSP代码)的次数与它的iterationCount参数所要求的次数相同。

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

+0

这是否意味着如果我在一个根本没有身体的标签(它只能通过阅读标签属性转换成html),这个调用没有效果? – Sephy 2011-12-30 16:29:35

+0

如果标签不接受正文,如果我正确读取javadoc,则该片段将为空。如果有一个身体,但它不包含任何字符,那么它将不起作用。如果它包含一个空白区域,则将向作者写入一个空白区域。 – 2011-12-30 16:51:29

+0

好吧,即使我仍然不明白为什么我在代码中有这个,它会更清晰一些。谢谢! – Sephy 2011-12-30 16:52:22