Components That Make Up a
Tag Library
The Tag Handler Class
Must implement javax.servlet.jsp.tagext.Tag
Usually extends TagSupport or BodyTagSupport
Goes in same directories as servlet class files and beans
The Tag Library Descriptor File
XML file describing tag name, attributes, and
implementing tag handler class
Goes with JSP file or at arbitrary URL
The JSP File
Imports a tag library (referencing descriptor file)
Defines tag prefix
Uses tags
79
JSP
www.corewebprogramming.com
Defining a Simple Tag Handler
Class
Extend the TagSupport class
Import needed packages
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
Override doStartTag
Obtain the JspWriter by means of pageContext.getOut()
Use the JspWriter to generate JSP content
Return SKIP_BODY
Translated into servlet code at page translation time
Code gets called at request time
80
JSP
www.corewebprogramming.com
40