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

Viewed 9617

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>  
3 Answers

The Jakarta EE 9 version of JSTL is available as JSTL 2.0 here.

<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>jakarta.servlet.jsp.jstl</artifactId>
    <version>2.0.0</version>
</dependency>

This is the reference implementation of JSTL 2.0 which is currently also used in GlassFish 6.0 (originally from Sun, then owned by Oracle, then owned by Eclipse). Usually Apache also has its own implementation, but it is not available as JSTL 2.0 (yet?).

For sake of completeness, and to confirm, yes the taglib URI of JSTL 2.0 still references the original java.sun.com host whereas you'd intuitively expect it also being migrated to xmlns.jcp.org or even jakarta.ee.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

See also:

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.

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

Related