在sun官方文檔上有下面這樣一段話。
The following is a non-normative, brief overview of the SimpleTag lifecycle. Refer to the JSP Specification for details.
A new tag handler instance is created each time by the container by calling the provided zero-args constructor. Unlike classic tag handlers, simple tag handlers are never cached and reused by the JSP container.
The setJspContext() and setParent() methods are called by the container. The setParent() method is only called if the element is nested within another tag invocation.
The setters for each attribute defined for this tag are called by the container.
If a body exists, the setJspBody() method is called by the container to set the body of this tag, as a JspFragment. If the action element is empty in the page, this method is not called at all.
The doTag() method is called by the container. All tag logic, iteration, body evaluations, etc. occur in this method.
The doTag() method returns and all variables are synchronized.
必知必會:簡單标簽也是一個标簽,是以聲明的過程也Tag的一樣,同樣是三步。
建立繼承SimpleTag類的實作類,重寫doTag方法
在tld檔案中進行嚴格的聲明
在jsp頁面中taglib的命名空間及标簽字首的聲明,然後進行調用自定義的簡單标簽
第一步:建立實作類:
在tld檔案中進行相關限制項的配置:
第三步:在jsp頁面中進行聲明然後調用:
總結:
簡單标簽可以替代BodyTag接口完成同樣的操作,但是有更加的簡單和輕便
簡單标簽lifeCycle邏輯清晰,調用規則明确
使用相關流對象就可以完成對标簽體的操控maniplate