How do I use JSTL on my JSPs?
Author: Deron Eriksson
Description: This Java tutorial describes how to use JSTL on JSPs.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 1.5.1 || Tomcat 5.5.20


Page: < 1 2

(Continued from page 1)

So, you may be wondering, how does this all hook together? Why can you enter the taglib directive at the top of your jspW, and 'magically' you are able to use the 'c' JSTLSW library?

It turns out that the 'uri' taglib is actually defined in the JSTL standard.jar file. If you open the JSTL standard.jar file, within its META-INF directory, you can see the tag libraries that are definted by the standard jarW file via the tld files.

contents of standard.jar's META-INF directory

If you open the c-1_0.tld file, you can see that the uri reference in our jsp's taglib directive, "http://java.sun.com/jstl/core", is contained within this tld in its uri tag and thus allows us to map our jsp taglib directive to this tld description.

c-1_0.tld displayed in WordPad

If we scroll down through the c-1_0.tld file, we can find the tag named 'out', which corresponds to our jsp's c:out tag. As we can see, the tld describes this tag and its various attributes. In addition, we can see that this tag maps to the OutTag class, which is the class that actually implements this tag's behavior.

'out' tag in c-1_0.tld

As you can see, JSTL is quite easy to set up and use, and EclipseSW has some nice features such as code-completion for tag libraries. In addition, the mapping from the jsp taglib directive to the tld within a jar file and the mapping from a jsp JSTL tag to the actual JavaSW class within the JSTL jar file is actually quite straightforward.

One thing you might want to do is add version numbers to your jstlSW jar files. In the example above, I downloaded the version 1.1.2 jstl.jar and standard.jar files, although the version number wasn't explicitly put on the file name. One way to figure out the version number is to open up the jar file and examine the META-INF/MANIFEST.MF file, which typically has a version number within it, such as "Implementation-Version: 1.1.2". Personally, I like to rename my jar files to have the version number on the file name, so I usually would rename these jar files to be jstl-1.1.2.jar and standard-1.1.2.jar.

Page: < 1 2