public int doStartTag() { try { JspWriter out = pageContext.getOut(); out.print("Custom tag example " + "(coreservlets.tags.ExampleTag)"); } catch(IOException ioe) { System.out.println("Error in ExampleTag: " + ioe); }
return(SKIP_BODY); } } 2. Tag Library Descriptor: <?xml version="1.0" encoding="UTF-8"?> <taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"> <tlib-version>1.0</tlib-version> <short-name>mytld</short-name> <uri>/WEB-INF/tags/mytld.tld</uri> <!-- A validator verifies that the tags are used correctly at JSP translation time. Validator entries look like this: <validator> <validator-class>com.mycompany.TagLibValidator</validator-class> <init-param> <param-name>parameter</param-name> <param-value>value</param-value> </init-param> </validator> --> <!-- A tag library can register Servlet Context event listeners in case it needs to react to such events. Listener entries look like this: <listener> <listener-class>com.mycompany.TagLibListener</listener-class> </listener> -->
<tag> <name>myTag</name> <tagclass>coreservlets.tags.HelloTag</tagclass> <info>Simplest example: inserts one line of output</info> <bodycontent>EMPTY</bodycontent> </tag>