Taglibs : Java Glossary

Taglibs
One of many add-ons to JSP (Java Server Pages). 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 (Hypertext Markup Language) 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 Server Pages 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 (extensible Markup Language) is being used and which encoding.
<taglib Miscellaneous information about where to find a DTD (Document Type Definition) 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 ofjavax.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 implementjavax.servlet.jsp.tagext.Tag, either from scratch or by extendingjavax.servlet.jsp.tagext.SimpleTag orjavax.servlet.jsp.tagex.TagSupport.

You must write getters and setters for each parameter, and aSimpleTagSupport.doTag orTagSupport.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 (Uniform Resource Locator) of the page you are generating is trickier:

Including

There are several ways you might include boiler plate text:

Learning More


SimpleTag interface : available:
SimpleTagSupport : available:
JspContext : available:
Tag interface : available:
TagSupport : available:
TagExtraInfo : available:
PageContext : 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
logofeedback Please email your feedback for publication, letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email If you want your message kept confidential, not considered for posting, please explicitly specify that.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.210]
You are visitor number 11,522.