Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core” - Cause and Solution

This error comes in when you are trying to use the JSTL core tag library in your JSP page but web container is not able to locate corresponding TLD files, also known as tag library descriptor. In order to use the custom tags in the JSP page, the first step is to import them using @taglib directive and for that purpose, we provide a URI. Many JSP developer thinks this is the location where TLD files are stored but that's not true, this is actually the value, custom tab library developer has put in the URL field of tag library descriptor. This misunderstanding causes lots of trouble while solving "Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core”.

We will see how the web container finds TLD files and what are possible causes for this error in the next section. Another thing to keep in mind particular to this error is that JSTL uses different URL in a different version, for example in JSTL 1.0 the URI for JSTL custom tags were http://java.sun.com/jstl/core", mind it there was no "/jsp", but from JSTL 1.1 the URI changed to "http://java.sun.com/jsp/jstl/core".

So, sometimes, if you have JSTL 1.0 jars in your classpath (under WEB-INF/lib) folder but specifying URI as "http://java.sun.com/jsp/jstl/core" in taglib directive you get this error.

Btw, if you are new into Servlet and JSP world then you can also check out JSP, Servlets, and JDBC for Beginners: Build a Database App course to learn about JSP and JSTL basics which are important to use these tag libraries in your project.





What is "Can not find the tag library descriptor"

When JSP developer wants to use custom tag they first import it using taglib directive by providing a URI. Web container looks that URI and searches for that in all the tag library descriptor available in following four locations:

1) Inside the WEB-INF directory of your web application

2) Inside a subdirectory of WEB-INF folder like  WEB-INF/TLDs

3) Inside the META-INF directory of a JAR file stored in WEB-INF/lib folder

4) Inside a sub-directory of META-INF inside a JAR file that’s inside WEB-INF/lib

If a web container doesn't find that URI then it throws "Can not find the tag library descriptor" error followed by the URL it is not able to find. So in our case, an error message is "Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core”, which means web container is not able to find TLD files for URI "http://java.sun.com/jsp/jstl/core", which is for JSTL core tag library version 1.1.

Since JSTL tag libraries are bundled inside standard.jar, you should have that JAR in your Web application's classpath like WEB-INF/lib. JSTL TLDs for all tags like core,xml SQL, and formatting are actually inside the META-INF folder of standard.jar.

So the first thing you should check is whether standard.jar and JSTL.jar is inside your WEB-INF/lib folder or not, if not please add it by copying it from Tomcat's example folder or downloading it via Maven or copying from your build host.

Sometimes you get the error "Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core” even after having jstl.jar and standar.jar in your classpath or WEB-INF/lib directly, in that case, please check the version of JSTL and standard.jar.

Since URI is different in JSTL 1.1 and JSTL 1.0, you must use the right version of JAR corresponding to the URI you are using in your JSP page.

This means, If you are using http://java.sun.com/jsp/jstl/core, add JSTL, and standard 1.1 JAR. And

If you are using http://java.sun.com/jstl/core, (no /JSP in URI) then put JSTL 1.0 and standard 1.0 JAR in the WEB-INF lib folder.

Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core” - Cause and Solution


Shortcuts

1) Check whether you have standard.jar in your classpath because TLDs are inside that.

2) Check whether standard.jar is inside WEB-INF/lib

3) Check you are using JSTL 1.1 and standard 1.1 JAR because URI "http://java.sun.com/jsp/jstl/core" need JSTL1.1 jar files

4) Use the URI as "http://java.sun.com/jstl/core" if you are using JSTL 1.0 JAR, remember there is no JSP in URI.

That's all about how to fix "Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core” error in Java web application.  Just remember that URI is different in JSTL 1.1 and JSTL 1.0, you must use the right version of JAR corresponding to the URI you are using in your JSP page and you need to use different versions of JAR files depending upon the URI you are using in the JSP file.

Further Learning
Java Web Fundamentals By Kevin Jones
Spring Framework 5: Beginner to Guru
JSP, Servlets and JDBC for Beginners: Build a Database App


Other Java troubleshooting articles you may like:
  • java.sql.SQLException: No suitable driver found for 'jdbc:MySQL://localhost:3306/mysql [Solution]
  • How to solve java.lang.ClassNotFoundException: com.mysql.jdbc.Driver error? (hint)
  • java.sql.SQLServerException: The index 58 is out of range - JDBC (solution)
  • How to fix Caused By java.lang.NoClassDefFoundError: org/apache/log4j/Logger (solution)
  • How to fix 'javac' is not recognized as an internal or external command (solution)
  • java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory error (solution)
  • Common reasons for java.lang.ArrayIndexOutOfBoundsException in Java? (solution)
  • 10 common reasons for java.lang.NumberFormatException in Java? (tutorial)
  • How to fix the "illegal start of expression" compile-time error in Java? (tutorial)
  • Cause and solution of "class, interface, or enum expected" compiler error in Java? (fix)
  • How to avoid ConcurrentModificationException in Java? (tutorial)
  • How to solve java.lang.OutOfMemoryError: Java Heap Space in Eclipse, Tomcat? (solution)
  • How to fix "Error: Could not find or load main class" in Eclipse? (guide)
  • How to solve java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver? (solution)
  • org.Spring framework.Web.Context.ContextLoaderListener (solution)
  • How to connect to the MySQL database in Java? (tutorial)
  • Fixing java.lang.UnsupportedClassVersionError Unsupported major.minor version 50.0 (solution)
  • How to solve "could not create the Java virtual machine" error in Java? (solution)
  • How to solve "variable might not have initialized" compile-time error in Java? (answer)
Thanks for reading this article, if you like this article then please share with your friends and colleagues too. If you have any doubt or questions then please drop a comment.

P. S. - If you are new into Servlet and JSP and looking for some free online courses to start with then you can also check out this list of free Servlet and JSP courses for beginners. They are good to learn the basics of Servlet and JSP. 

No comments:

Post a Comment