12

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>  
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Can you show your dependencies? – dan1st Oct 29 '20 at 19:33
  • I am a beginner but I have just written a simple index jsp file to try a simple jstl code, in webapps in CATALINA_HOME I have created the basic directory structure but I have not created a deployment descriptor(web.xml) as it is not necessary here, I am using jakarta apache tomcat 10 with has jakarta.* packages instead of javax.* – Faizan Shaikh Sarkar Oct 29 '20 at 19:39
  • Do you use maven? In this case, can you show your pom.xml? If not, can you show your Build Path/Project Structure? – dan1st Oct 29 '20 at 19:42
  • You need to include jstl library in your project. If it is Spring project then include as dependency other include as library . – Sanjay Oct 30 '20 at 04:56
  • @dan1st No I don't, this is my first program using JSTL, I have not used pom, I am just trying to use simple core library c:out to see if it all works correctly. – Faizan Shaikh Sarkar Oct 30 '20 at 05:32
  • @Sanjay I have, I am using taglibs-standard-compat-1.2.5.jar, taglibs-standard-impl-1.2.5.jar, taglibs-standard-jstl-el-1.2.5.jar, taglibs-standard-spec-1.2.5.jar; currently I am using these 4 libraries but before I was using jstl.jar, jstl-impl.jar, jstl-standard.jar with jakarta tomcat 10 as well but nothing worked. I saw many tutorials and examples working the way I tried without deployment descriptors and pom by just following the basic directory structure with only index.jsp but it is still not working, I have java 8 installed Java 8 and jakarta Tomcat 10, please help. – Faizan Shaikh Sarkar Oct 30 '20 at 05:42

3 Answers3

17

The Jakarta EE 9 / Servlet 5.0 compatible 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" %>

In case you're already on Jakarta EE 10 / Servlet 6.0 (e.g. Tomcat 10.1.x instead of Tomcat 10.0.x), then use JSTL 3.0 instead.

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

With this version, the taglib URI has been changed to from the URL form to the URN form as follows:

<%@ taglib uri="jakarta.tags.core" prefix="c" %>

See also:

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
6

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.

S.Dave
  • 151
  • 2
  • 4
0

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
dhtx2
  • 1