ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button JSP and Servlets

Jakarta Taglibs


Why are tag libraries popular these days? One reason is that JSP development often consists of many tasks that are common and repeatable; an obvious solution is to incorporate common and functionality into tag libraries, which can then be reused over the course of many projects. Wouldn't it be great if there were existing libraries that everyone could use without having to write them? Welcome to the Taglib project of Jakarta. This article will discuss the Taglib project and how you can take advantage of some great open source tag libraries.

What are Tag Libraries?

If you are new to JSP development, custom tag libraries are something that you'll want to become familiar with. Custom tags are a way to separate presentation from logic. If you have tasks that are being done repetitively they are probably good candidates to be incorporated into a tag library. Incorporating them into the tag library makes life easier for the page designer because if there are logic changes, they can be handled within the tag library. There is no need to actually change the JSP. This also means that if there are page layout changes, there is no need to change the logic. Using tag libs makes for more maintainable JSP.

Custom tags can modify content within a tag body and have access to the application context. Custom tags can be used to generate dynamic content as well as to implement flow control. Additionally, tags can interact with other tags as well as be nested within each other. For a full description of using and building your own custom tag libraries, see my previous two articles, Building Custom Tag Libraries, and Advanced Custom Tag Libraries.

The Land of Jakarta

The Jakarta Taglib project is an open source repository of tag libraries. We'll go into a brief description of what's available, what each one does, and situations in which you might want to use each. For those who aren't familiar with open source, it might be time to find out more about it.

Also in JSP and Servlets:

Learning the New Jakarta Struts 1.1, Part 2

Learning the New Jakarta Struts 1.1, Part 1

JSP Standard Tag Libraries, Part 2

JSP Standard Tag Libraries, Part 1

Learning Jakarta Struts, Part 3

Comment on this articleSo there you have it. Hours of coding (not to mention debugging) saved by using one of the many available taglibs from the Jakarta project. As you can see, there are many available taglibs, and chances are some of them have tags that you probably could use in your current applications that use JSP. So why reinvent the wheel?
Post your comments

The Jakarta Project is actually an umbrella project for many other projects which aim to deliver commercial-quality Java server programs. All of the projects are open source and are developed by programmers throughout the world. Anyone can participate, but there are guidelines as to how source code gets updated in the CVS repository. There is always a need for more open source programmers, so maybe this article will add a few new faces to the contributing developer list.

You may already have heard of some Jakarata projects: Tomcat, a JSP/Servlet engine, ANT, a make-like build environment, or Structs, a framework based on the MVC pattern for JSP. This article focuses on the Taglib project, but you should take the time to become familiar with some of the others. There is some useful stuff out there if you know where to look. For a complete list of Jakarta projects, go to http://jakarta.apache.org.

It is possible to download just binaries or complete source code for all of the projects. Sometimes all you need is a binary or jar file. If you need to modify any of the functionality, obviously you will want the source code. Each project details how to retrieve and build from source. And it's a relatively straightforward process.

Pages: 1, 2, 3

Next Pagearrow