The four files you touch

#WhereWhat
1src/<package>/MyTag.javathe tag handler class
2WEB-INF/tags/mylib.tldmaps each tag name to its handler class and attributes
3WEB-INF/web.xml (optional)maps a logical URI to the TLD, if the page uses a URI instead of a path
4any .jspthe taglib directive plus the tag itself

Classic (TagSupport) vs simple (SimpleTagSupport)

Classic — TagSupport
Session 3
Simple — SimpleTagSupport
Session 7
Methods you writedoStartTag(), doAfterBody(), doEndTag()doTag() only
Return valuesEVAL_BODY_INCLUDE, EVAL_BODY_AGAIN, SKIP_BODY, EVAL_PAGEnone — just write to the output and return
Repeating the bodyexplicit, via doAfterBody() + EVAL_BODY_AGAINjust a for or while loop inside doTag()
Getting the writerpageContext.getOut()getJspContext().getOut()
JSP version needed1.22.0
Use it whenyou must support old containersnew code — far more readable

Gotchas

← Back to the example index