Taglibs : Java Glossary

go to home page T words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all) ©1996-2009 Roedy Green, Canadian Mind Products
Taglibs
One of many add-ons to JSP. A library of standard functions so you can do things in JSP without having to write Java code. They have their own syntax unlike either HTML or Java. I consider the syntax unspeakably ugly. There are many such libraries, all generically called TagLibs. The one with the most official status is called JSTL (Java Standard Tag Library).

*.tld files

Besides writing some Java code to implement your tag, you must create a *.tld file containing xml to tell the womb a few facts about your tags.
Basic Taglib tld Tags
tag purpose
<?xml Which version of XML is being used and which encoding.
<taglib Miscellaneous information about where to find a DTD to describe the xml grammar of the file
<description> Surrounds some text documenting what this jsp-tag as whole is for.
<tag> Surrounds tags describing one jsp tag.
<tag-class qualified class name that implements javax.servlet.jsp.tagext. Tag to implement this jsp tag.
<teiclass optional subclass of javax.servlet.jsp.tagext.TagExtraInfo.
<body-content Can have the values empty, JSP, scriptless or tagdependent. A one-liner jsp tag would have an empty body. A jsp tag that surrounded some text would be set to JSP to evaluate the body of the tag.
<info> Documenation on what this jsp tag is for.
<variable> Surrounds tags describing one EL variable exposed to the calling page.
<attribute> Surrounds tags describing one parameter of the jsp tag.
<name Name of the keyword parameter used in the jsp files when the tag is invoked. Your handler will be passed the value of the parameter via its setXxx method where xxx matches the name of the keyword parameter.
<required true if the parameter must be present.
<rtexprvalue by default false. If true, the user may calculate this parameter’s value with a scriptlet.
I don’t see any way to pass arrays or varargs as parameters.

Java Code to Implement a Custom Tag

Your Java code to implement a custom tag must implement javax.servlet.jsp.tagext.Tag, either from scratch or by extending javax.servlet.jsp.tagext.SimpleTag or javax.servlet.jsp.tagex.TagSupport.

You must write getters and setters for each parameter, and a SimpleTagSupport.doTag or TagSupport.doStartTag method to generate the HTML from the parameter values.

Navigating

In SimpleTagSupport is a method getJspContext. From JspContext you can find a few other control objects such as JspWriter with getOut where you write the expanded HTML.

Oddly, TagSupport has a completely different way of finding associated information. TagSupport has a protected field called pageContext. From there you can find the other control objects such as: JspWriter with getOut where you write the expanded HTML, Servlet with getPage, ServletRequest with getRequest, ServletResponse with getResponse, ServletConfig with getServletConfig and ServletContext with getServletContext.

Most of the navigation in convoluted, but straightforward. Getting the URL of the page you are generating is trickier:

Including

There are several ways you might include boiler plate text:

Learning More

SimpleTag interface : available:
Servlet interface : available:
ServletRequest interface : available:
ServletResponse interface : available:
ServletConfig interface : available:
ServletContext interface : available:
javax.servlet.http.HttpServlet docs : available:
javax.servlet.http package docs : available:
javax.servlet package docs : available:

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/taglibs.html J:\mindprod\jgloss\taglibs.html
CMP logofeedback Please email your feedback for publication, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.191.108]
You are visitor number 8,861.