Jsp2 custom tag
To open a custom tag in jsp:
1. Development of custom tag processing class
2. Create a *. tid file. Each tld tag corresponds to a tag library, and each tag library corresponds to multiple tags.
3. Use tags in jsp
* *** Precautions for developing custom tag classes:
1. The custom label class should inherit a parent class javax. servlet. jsp. tagext. SimpleTagSupport
2. If the custom label class contains attributes, each attribute should have the corresponding getter/setter method.
3. Override the doTag () method. This method is used to generate page content.
Example:
Public class HelloWorldTag extends simpleTagSupprt {
// Rewrite the doTag () method
Public void doTag () throws JspException, IoException {
This. getJspContext (). getOut (). write ("Hello World" + new Date ())
}
}
* *** Create a TLD tag
TLD is the abbreviation of Tag Library Definition, that is, Tag Library Definition.
We can copy a file template \ webapps \ examples \ WEB_INF \ jsp2 in tomcat contains a jsp2-example-taglib.tld
Copy the file to the web application's WEB-INF path and make simple modifications
Example:
Root Node:
Tag:
* *** Use tags <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + signature + MqGkILHqx6nD + signature + PGJyPgo8L3A + CjxwPsq508Ox6sepv + signature + MaGkILW8yOux6sepv + signature/Signature "http://tomcat.apache.org/debug-taglib" prefix = "mytag" %>
Uri: The uri of the tag library.
Prefix: short name
2. Use tags; use custom tags in jsp
Because of
TAGDEPENDENT Empty TAG body defined
We only need to call:
Prefix + Tag Name