JSTL (JSP Standard Tag Library) is a JSP based standard tag library which offers tags to control the flow in the JSP page, date/number formatting and internationalization facilities and several utility EL functions.
JSTL (JSP Standard Tag Library) is a JSP based standard tag library which offers <c:xxx>
tags to control the flow in the JSP page, <fmt:xxx>
tags for date/number formatting and internationalization facilities and several ${fn:xxx()}
utility EL functions.
Note that JSTL also offers SQL and XML taglibs which enable a declarative manner of executing SQL queries and parsing XML inside a JSP page. This is however discouraged for other purposes than quick prototyping. In the real world both tasks need to be done by real Java classes which are (in)directly controlled/delegated by a Servlet.
JSTL is part of the Java EE API and included in Java EE application servers such as WildFly, TomEE, GlassFish, but not in barebones servletcontainers such as Tomcat and Jetty. JSTL are the taglibs which you import from http://java.sun.com/jsp/jstl/*
namespace. JSTL must not be confused with a "custom JSP tag library" (wherein you define a .tld
file yourself). JSTL must also not be confused with taglibs of 3rd party frameworks such as JSF, Spring MVC, Struts, Displaytag, etcetera. JSTL must also not be confused with Expression Language (EL) (which are those ${}
things).
Installing JSTL
Head to following answer how to install JSTL: How to install JSTL? The absolute uri: http://java.sun.com/jstl/core cannot be resolved
JSTL version history and taglib URIs
JSTL was available in different versions:
1.0: Invented by Apache/Jakarta. Composed of two JAR files
jstl.jar
(the API) andstandard.jar
(the impl). Taglib URI has no/jsp
in path likehttp://java.sun.com/jstl/core
and the prototype version has the library name suffixed with_rt
likehttp://java.sun.com/jstl/core_rt
. Came along with and requires at minimum Servlet 2.3 / JSP 1.2.1.1: Integrated as part of J2EE 1.4. EL was moved from JSTL to JSP. Taglib URI includes
/jsp
in the path likehttp://java.sun.com/jsp/jstl/core
. Came along with and requires at minimum Servlet 2.4 / JSP 2.0.1.2.x: Integrated as part of Java EE 5 and newer. Taglib URI has not changed and is still like
http://java.sun.com/jsp/jstl/core
. Came along with Servlet 2.5 / JSP 2.1 but works at Servlet 2.4 / JSP 2.0 as well.2.x: Integrated as part of Jakarta EE 9 and newer. The only change is the rename of
javax.*
package tojakarta.*
package. Taglib URI has not changed and is still likehttp://java.sun.com/jsp/jstl/core
. Came along with Servlet 5.0 / JSP 3.0 and is not backwards compatible in any way due to package name change.3.x: Integrated as part of Jakarta EE 10. The Taglib URI changes to
jakarta.tags.core
.Facelets: Facelets, the successor of JSP, has among the provided taglibs a selected subset of JSTL 1.2 core and the full set of JSTL 1.2 functions builtin. This requires a minimum of JSTL 1.2. For Facelets 1.x the XML namespace URI is
http://java.sun.com/jstl/core
and for Facelets 2.x the XML namespace URI ishttp://java.sun.com/jsp/jstl/core
with (confusingly!) the/jsp
part and from Facelets 2.2 onwards the namespace URI ishttp://xmlns.jcp.org/jsp/jstl/core
.
Help! The expression language (EL, those ${}
things) doesn't work in my JSTL tags!
Head to following answer for explanation: EL expressions not evaluated in JSP
Online resources
- Java EE 5 tutorial - JavaServer Pages Standard Tag Library
- JSR 52: A Standard Tag Library for JavaServer Pages™
Frequently asked questions
- How to loop over a
Map
(andList
) in<c:forEach>
? - How to internationalize a Java web application with JSTL
fmt
taglib? - JSTL in JSF2 Facelets... makes sense?