JSP Standard Tag Library eases Webpage development
Learn how JSTL improves upon JSP for simpler Webpage implementation
By Steve Small, JavaWorld.com, 02/28/03
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
The 1996 introduction of Java servlets made Java a reasonable choice for dynamic Webpage development. The subsequent debut
of JavaServer Pages (JSP) followed by the inclusion of support for JSP tags were logical evolutionary steps toward fast, maintainable
Java Webpage implementation. But the mid-2002 release of JSTL (JSP Standard Tag Library) represents perhaps the biggest step
yet in speeding and simplifying the development process further.
In this article, I explain JSTL's capabilities and cover everything you need to get started with JSTL. It's assumed you have
a basic understanding of Java, JSP, XML, and setting up a Web container. If you're not comfortable with these topics, you
might want to browse the background references in Resources. Additional assumed knowledge is described in the XML and SQL sections below.
Installing JSTL support
For our JSTL installation example, we use Tomcat 4.1 (although any servlet container that supports the Servlet 2.3 and JSP
1.2 specifications should work). First, download Tomcat and follow the setup instructions. (Note that JSTL requires a JSP 1.2 Web container.)
Start Tomcat with tomcat4 start and load the index.html page to make sure Tomcat is alive and well.
Next, you'll need to install JSTL support. You can download JSTL support from the Jakarta Website then follow these steps:
- Download the JSTL archive (binaries not source) from the Jakarta Website. Unzip/untar the file.
- Copy the jar files you've extracted to
common/lib in your Tomcat installation (although you won't need all the jar files for our project). This makes the JSTL jar files available
to any of your Web applications.
- For any Web application for which you want to use JSTL, copy the
.tld files to the WEB-INF directory in your Web application.
- For your JSTL Web application, edit your
web.xml file and add the following entries:
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
<taglib-location>/WEB-INF/sql.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
<taglib-location>/WEB-INF/x.tld</taglib-location>
</taglib>
These entries let your Web application use the expression language (EL) versions of the JSTL tag libraries. Position of these
entries matters! If you're not sure where to put them, the definitive guide to web.xml options and ordering is defined in the document type definition (DTD) at: http://java.sun.com/j2ee/dtds/web-app_2_2.dtd.
- When you create a JSP page that uses JSTL, put it in your Web application's main directory, just like other JSP and HTML pages.
You can name this page whatever you want, but it should have a
.jsp extension.
The basics
First, all JSTL pages are also JSP pages. JSTL is just a superset of JSP functionality.
Also, all JSTL tags are valid XML. That means if you treat the context of a page outside the JSTL tags as template text (which
will normally be HTML), the remaining JSTL tags must parse as valid XML. This has some important implications, most of which
are good.
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Resources
- Background references:
- Download Tomcat
http://jakarta.apache.org/tomcat
- Marty Hall's JSP/servlet tutorial
http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/
- Sun Microsystems' servlets and JSP tutorial
http://java.sun.com/products/jsp/docs.html
- Sun's XML introduction
http://java.sun.com/xml/tutorial_intro.html
- Internationalization support in Java (The Java Tutorial)
http://java.sun.com/docs/books/tutorial/i18n/
- SQL basics
http://www.firstsql.com/tutor.htm
- James Goodwill's "Java Web Applications" (onJava.com, March 15, 2001) covers Web containers with an emphasis on Tomcat
http://www.onjava.com/pub/a/onjava/2001/03/15/tomcat.html
- JSTL references:
- JSTL support page
http://jakarta.apache.org/taglibs/doc/standard-doc/intro.html
- JSTL archive download page
http://apache.towardex.com/jakarta/taglibs/standard/
- The definitive guide to web.xml options and ordering is defined in the document type definition (DTD) at
http://java.sun.com/j2ee/dtds/web-app_2_2.dtd
- The JSTL specificationthe final word on all things JSTL (at least until the next version). As Java specifications go, this
one is very readable
http://www.jcp.org/aboutJava/communityprocess/first/jsr052/
- Shawn Bayern's JSTL in Action (Manning Publications Company, 2002; ISBN1930110529) is an outstanding introduction to JSTL
http://www.amazon.com/exec/obidos/tg/detail/-/1930110529/javaworld
- I've only skimmed David Geary's Core JSTLMastering the JSP Standard Tag Library (Prentice Hall, 2002; ISBN0131001531), but based on the numerous excellent Java books David has turned out in the past, this
is likely to be worth having
http://www.amazon.com/exec/obidos/tg/detail/-/0131001531/javaworld
- Other online introductions to JSTL:
- "JSTL 1.0Standardizing JSP, Part 1" Hans Bergsten (onJava.com, August 14, 2002)
http://www.onjava.com/pub/a/onjava/2002/08/14/jstl1.html
- "JSTL 1.0What JSP Applications Need, Part 2," Hans Bergsten (onJava.com, November 11, 2002)
http://www.onjava.com/pub/a/onjava/2002/09/11/jstl2.html
- Sun's The Java Web Services Tutorial
http://java.sun.com/webservices/docs/1.0/tutorial/doc/JSTL.html
- JavaWorld resources:
- David Geary briefly discusses JSTL in his series, "A First Look at JavaServer Pages:"
-
- Browse the JavaServer Pages section of JavaWorld's Topical Index
http://www.javaworld.com/channel_content/jw-jsp-index.shtml
- David Geary's Java Design Patterns column in JavaWorld
http://www.javaworld.com/columns/jw-java-design-patterns-index.shtml
- Visit JavaWorld's Enterprise Java discussion
http://forums.devworld.com/webx?50@@.ee6b80a
- Sign up for JavaWorld's free weekly Enterprise Java email newsletter
http://www.javaworld.com/subscribe
- You'll find a wealth of IT-related articles from our sister publications at IDG.net
For those reading this article, *don't* use the method specifiedBy Anonymous on October 18, 2009, 9:59 amFor those reading this article, *don't* use the method specified above to get JSTL to work with your JSP pages. A better and standard approach is to place the "jstl.jar"...
Reply | Read entire comment
wowBy Anonymous on October 13, 2009, 2:02 amwow
Reply | Read entire comment
testBy Anonymous on September 2, 2009, 1:56 pmtest
Reply | Read entire comment
By Anonymous on October 29, 2008, 7:28 am
Reply | Read entire comment
View all comments