'jakarta.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/jsp/tagext/TagLibraryValidator

I am trying to execute JSP with JSTL, but I am not able to. I have Apache Tomcat 10, i.e. jakarta.servlet.* instead of javax.servlet.*. So whenever I execute the web app with JSTL 1.2.5 files, then I get the error:

jakarta.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/jsp/tagext/TagLibraryValidator
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:778)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

I tried to find a similar problem/question online that is resolved, but was not able to find it. How can I use JSTL in JSP with Tomcat 10?

My index JSP file code:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<html>  
  <head>  
    <title>Tag Example</title>  
  </head>  
  <body>  
    <c:out value="${'Hello Yo'}"/> 
  </body>  
</html>  


Solution 1:[1]

For your configuration you will need both these files for the JSTL to work properly:

If you put them in the lib folder of the project, then it would only work for that app. So I suggest you putting them in the lib folder of your TomCat app (.../apache-tomcat-10.0.6/lib/) amongst the other jar files.

This is a pretty good topic that discusses the matter in details.

Solution 2:[2]

For those who were once lost like me: You need to download the latest version of taglibs and jslt (together with their dependencies)!

Here's how it goes:

  1. Download the latest taglibs from Apache for Tomcat 10

  2. Download the latest jslt and dependencies - EXCEPT for jakarta.servlet-api-5.0.0.jar (here is why)

  3. Move the downloaded JARs into the project WEB-INF/lib folder, which should look like this:

.
+-- _WEB-INF
|   +-- lib
|       +-- jakarta.activation-2.0.0.jar
|       +-- jakarta.el-api-4.0.0.jar
|       +-- jakarta.servlet.jsp.jstl-2.0.0.jar
|       +-- jakarta.servlet.jsp.jstl-api-2.0.0.jar
|       +-- jakarta.xml.bind-api-3.0.0.jar
|       +-- taglibs-standard-compat-1.2.5.jar
|       +-- taglibs-standard-impl-1.2.5.jar
|       +-- taglibs-standard-spec-1.2.5.jar

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 S.Dave
Solution 2 Dharman