Taglibs : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

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 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> Documentation 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.Tagtagext.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.

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:


This page is posted
on the web at:

http://mindprod.com/jgloss/taglibs.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\taglibs.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[3.15.151.180]
You are visitor number