Questions tagged [jstl]

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) and standard.jar (the impl). Taglib URI has no /jsp in path like http://java.sun.com/jstl/core and the prototype version has the library name suffixed with _rt like http://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 like http://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 to jakarta.* package. Taglib URI has not changed and is still like http://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.

  • 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 is http://java.sun.com/jsp/jstl/core with (confusingly!) the /jsp part and from Facelets 2.2 onwards the namespace URI is http://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

Frequently asked questions

Related tag info pages

5464 questions
404
votes
8 answers

Evaluate empty or null JSTL c tags

How can I validate if a String is null or empty using the c tags of JSTL? I have a variable of name var1 and I can display it, but I want to add a comparator to validate it. I want to validate when it is null or empty (my…
user338381
  • 4,043
  • 3
  • 14
  • 4
340
votes
7 answers

How to use if-else option in JSTL

Is there an if-else tag available in JSTL?
Srinivasan
  • 10,548
  • 25
  • 58
  • 82
300
votes
12 answers

if...else within JSP or JSTL

I want to output some HTML code based on some condition in a JSP file. if (condition 1) { Some HTML code specific for condition 1 } else if (condition 2) { Some HTML code specific for condition 2 } How can I do that? Should I use JSTL?
testndtv
  • 43,898
  • 91
  • 265
  • 396
241
votes
4 answers

Check a collection size with JSTL

How can I check the size of a collection with JSTL? Something like:
Sergio del Amo
  • 71,609
  • 66
  • 148
  • 177
170
votes
3 answers

JSTL in JSF2 Facelets... makes sense?

I would like to output a bit of Facelets code conditionally. For that purpose, the JSTL tags seem to work fine: ... However, I'm not sure if this is a best practice? Is there another way to achieve my goal?
Jan
  • 8,569
  • 11
  • 44
  • 52
144
votes
16 answers

How to install JSTL? The absolute uri: http://java.sun.com/jstl/core cannot be resolved

I don't know what I've done incorrectly, but I can't include JSTL. I have jstl-1.2.jar, but unfortunately I get exception: org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jstl/core cannot be resolved in either web.xml or…
lukastymo
  • 23,992
  • 12
  • 50
  • 66
137
votes
11 answers

How to do if-else in Thymeleaf?

What's the best way to do a simple if-else in Thymeleaf? I want to achieve in Thymeleaf the same effect as

Hello!

Maciej Ziarko
  • 9,686
  • 12
  • 44
  • 68
125
votes
2 answers

Loop through a Map with JSTL

I'm looking to have JSTL loop through a Map and output the value of the key and it's value. For example I have a Map which can have any number of entries, i'd like to loop through this map using JSTL and output both…
Dean
  • 1,261
  • 2
  • 8
  • 4
122
votes
2 answers

Evaluate if list is empty JSTL

I've been trying to evaluate if this array list is empty or not but none of these have even compiled:
OscarRyz
  • 184,433
  • 106
  • 369
  • 548
118
votes
7 answers

How do you get the length of a list in the JSF expression language?

How would I get the length of an ArrayList using a JSF EL expression? #{MyBean.somelist.length} does not work.
GBa
  • 14,931
  • 15
  • 47
  • 67
112
votes
5 answers

JSP : JSTL's tag

Writing a JSP page, what exactly does the do? I've noticed that the following both has the same result:

The person's name is

The person's name is ${person.name}

Steve Kuo
  • 58,491
  • 75
  • 189
  • 247
112
votes
5 answers

How to get a index value from foreach loop in jstl

I have a value set in the request object like the following, String[] categoriesList=null; categoriesList = engine.getCategoryNamesArray(); request.setAttribute("categoriesList", categoriesList ); and this is how I iterate in jsp page <%…
Java Questions
  • 7,372
  • 37
  • 109
  • 169
106
votes
13 answers

Access Enum value using EL with JSTL

I have an Enum called Status defined as such: public enum Status { VALID("valid"), OLD("old"); private final String val; Status(String val) { this.val = val; } public String getStatus() { return val; …
IaCoder
  • 10,849
  • 10
  • 33
  • 45
104
votes
4 answers

Use JSTL forEach loop's varStatus as an ID

I want to use the count from the JSTL forEach loop, but my code doesnt seem to work.
produces
Mark W
  • 5,416
  • 13
  • 52
  • 90
101
votes
4 answers

How do I check two or more conditions in one ?

How do I check two conditions in one ? I tried this, but it raises an error:
Selva Kumar K.P.
  • 1,039
  • 2
  • 10
  • 10
1
2 3
99 100