1. Project structure
2, the implementation of the custom tag required to rely on
<dependency> <groupId>javax.servlet</groupId> <artifactid>servlet-api</ artifactid> <version>2.5</version> <scope>provided</scope> </ dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactid >jsp-api</artifactId> <version>2.2</version> <scope>provided</scope> </dependency>
3, Hellotag.java
PackageCom.tag;Importjavax.servlet.jsp.JspException;ImportJavax.servlet.jsp.JspWriter;ImportJavax.servlet.jsp.tagext.SimpleTagSupport;Importjava.io.IOException;/*** Created by Administrator on 2016/7/11.*/ Public classHellotagextendsSimpletagsupport {@Override Public voidDotag ()throwsjspexception, IOException {jspwriter out=Getjspcontext (). Getout (); Out.println ("Hello Custom tag!"); }}
4, Costom.tld
<taglib> <tlib-version>1.0</tlib-version> <jsp-version>2.0</jsp-version> <short-name>example tld</short-name> <tag> <name>hello </name> <tag-class>com.tag.hellotag</tag-class> < Body-content>empty</body-content> </tag></taglib>
5, index.jsp
<%@ taglib prefix= "ex" uri= ". /web-inf/custom.tld "%>
Note: There is a need to introduce a tag library
<%@ taglib prefix= "ex" uri= ". /web-inf/custom.tld "%>
6. Results
JSP Custom Label Hello Costom Tag Small example