1. Use of simple labels
1) use custom tags to control whether the page content (TAG body) is output
Public void doTag () throws JspException, IOException {
// JspFragment jf = this. getJspBody ();
// Jf. invoke (null );
// Equivalent to jf. invoke (this. getJspContext (). getOut ());
}
2) The simple tag controls whether the jsp content after the tag is executed
Public void doTag () throws JspException, IOException {
JspFragment jf = this. getJspBody ();
Jf. invoke (null );
Throw new SkipPageException ();
}
3) custom tags implement loop output of content (TAG body)
Public void doTag () throws JspException, IOException {
JspFragment jf = this. getJspBody ();
For (int I = 0; I <5; I ++ ){
Jf. invoke (null );
}
}
4) custom tag modification content (TAG body) -- case-sensitive Conversion
Public void doTag () throws JspException, IOException {
JspFragment jf = this. getJspBody ();
// To get the content in JspFragment, enter it in a buffer-containing Writer, // obtain the string
StringWriter sw = new StringWriter ();
Jf. invoke (sw );
String content = sw. toString (). toUpperCase ();
JspWriter out = this. getJspContext (). getOut ();
Out. write (content );
}
2. Custom tags with attributes
1) control the number of times that the TAG body loops are output
Add attribute variables and their setter methods to the tag processing class
Private int times;
Public void doTag () throws JspException, IOException {
JspFragment jf = this. getJspBody ();
For (int I = 0; I <times; I ++ ){
Jf. invoke (null );
}
}
Public void setTimes (int times ){
This. times = times;
}
Add the attribute description <attribute> </attribute> to the tld file.
...
<Attribute>
<Name> times </name>
<Required> true </required>
<Rtexprvalue> true </rtexprvalue>
</Attribute>
...
Demo <trexprvalue> true </rtexprvalue>
<Class3g: mySimpleTag5 times = "<% = 3 + 1%>">
Aaaaaaaaa <br>
</Class3g: mySimpleTag5>
2) explains the type conversion problem when passing parameters, and uses the transmission of Data to demonstrate parameter transfer of non-Basic Data Types
L add Data type members and their setter methods to the tag processing class
Private Date date;
Public void setDate (Date date ){
This. date = date;
}
L add attribute description to tld
<Attribute>
<Name> date </name>
<Required> true </required>
<Rtexprvalue> true </rtexprvalue>
<Type> java. util. Date </type>
</Attribute>
L call in jsp
<Class3g: mySimpleTag5 times = "3" date = "<% = new Date () %>">
Xxxxxxxx
</Class3g: mySimpleTag5>
From the path of the mouse programmer