4. Control label body content execution five times
Here This method is inherited the tag interface implementation class, this implementation class not only implements the tag interface, also has the tag interface sub-interface, namely Iterationtag
The Doafterbody () method and the Eval_body_again constant are added to the sub-interface, in order to achieve the label body repetition
Tagrepeat.java
Package Tag;import Javax.servlet.jsp.jspexception;import Javax.servlet.jsp.tagext.iterationtag;import Javax.servlet.jsp.tagext.tag;import javax.servlet.jsp.tagext.tagsupport;/** * @author: Snowing * @date : April 18, 2017 * control tag body content execution five times */public class Tagrepeat extends TagSupport {int x=5; @Overridepublic int doStartTag () throws Jspe Xception {return tag.eval_body_include;//here to get tag body contents} @Overridepublic int Doafterbody () throws Jspexception {// This method is the end of the label body, before the end of the tag execution x--;if (x>0) {return iterationtag.eval_body_again;//and then output once the label body content}else{return Iterationtag.skip_body;} End label Repeat}}
Servlet------>jsp Custom Label 4 (repeat tag body)