This article mainly introduces the JSP custom label IfElse and traverses the custom label, needs the friend to be possible to refer to under
The first example: a simple JSP custom label to get content: first create a JSP instance class and then inherit the Simpletagsupport class then implement the Dotag () method of the parent class In this method gets the contents of the tag body this.getjspbody (); returns the Jspfragment class, which invokes Invoke (This.getjspcontext (). Getout ()); This method can also be written in empty, the meaning of the expression is output to the browser; code as follows: public class SimpleDmeo1 extends Simpletagsupport { @Override public void Dotag () throws Jspexception, IOException { jspfragment js =this.getjspbody (); js.invoke (null); nbsp } } Then write TLD file Tag library description file, and JSP file, these are simpler if you do not want to execute a certain content to throw an exception throw new Skippageexception (); And the surface content will not be displayed Next is a JSP custom tag file with attributes code as follows: public class SimpleDmeo1 extends simpletagsupport { private int Co unts; public void setcounts (int counts) { this.counts = counts; } @Override public void DoTa G () throws Jspexception, IOException { jspfragment js =this.getjspbody (); for (int i=0;i<counts;i++) {// Loop fetch Js.invoke (NULL); } } } <descripTion>a Tag Library exercising Simpletag handlers.</description> <tlib-version>1.0</ tlib-version> <short-name>c</short-name> prefix name <uri>http://www.csdn.com</uri > <tag> <name>demo</name> <tag-class>com.csdn.simple.SimpleDmeo1< /tag-class> <body-content>scriptless</body-content> <attribute> <name >counts</name> <required>true</required> <rtexprvalue>true</ rtexprvalue> </attribute> </tag> then; the contents of the JSP file the code is as follows: <hbsi: Demo counts= "3" >aaaaaaa<br/></hbsi:demo>//Output three series Jspfragment js = this.getjspbody (); StringWriter JW = new StringWriter (); Js.invoke (JW); String s = jw.tostring (). toUpperCase (); JspWriter Out =this.getjspcontext (). Getout (); for (int i=0;i<counts2;i++) { out.print (s); } }&NBsp This is converted to uppercase code, the others are consistent; about if else code, too much, I put in the resources, if necessary, can download, for reference only.