1
votes

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>  
1
Can you show your dependencies? - dan1st
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
Do you use maven? In this case, can you show your pom.xml? If not, can you show your Build Path/Project Structure? - dan1st
You need to include jstl library in your project. If it is Spring project then include as dependency other include as library . - Sanjay
@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

1 Answers

5
votes

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: