Making a Simple tag handler

For the simplest of Simple tags, the process is...simple.

  1. Write a class that extends SimpleTagSupport

    package foo;
    import javax.servlet.jsp.tagext.SimpleTagSupport;
    // more imports needed
    public class SimpleTagTest1 extends SimpleTagSupport {
       // tag handler code here
  2. Override the doTag() method

    image with no caption
  3. Create a TLD for the tag

    <taglib ...>
         <description>worst use of a custom tag</description>
  4. Deploy the tag handler and TLD

    Put the TLD in WEB-INF, and put the tag handler inside WEB-INF/classes, using the package directory structure, of course. In other words, tag handler classes go in the same place all other web app Java classes go.

    image with no caption
  5. Write a JSP that uses the tag

    <%@ taglib prefix="myTags" uri="simpleTags" %>

Get Head First Servlets and JSP, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.