3

I'm trying to use jstl in my project but i encountered the following problems when running the app on TomCat 10:

Description: The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception:

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

i added jstl.jar standard.jar jst-impl.jar jstl-standar.jar jstl-api-1.2.jar (according to diffrent tutorials) but yet none of them had solved the problem.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
yahyaBdd
  • 53
  • 1
  • 7

2 Answers2

4

Study that first line of error message. On the left, notice jakarta.. On the right, notice javax..

Java EEJakarta EE

A few years ago, Oracle transferred ownership and control of the Java Enterprise Edition (Java EE) specifications and technologies to the Eclipse Foundation. Thus, Java EE became Jakarta EE. The trademark Java is owned by Oracle Corp., and so that term must be removed from new artifacts produced by the Eclipse Foundation.

As part of that handover transition, the package naming changed from javax.* to jakarta.*.

You are using a version of Apache Tomcat, v 10, built for the jakarta.* package naming. The Tomcat community is developing another version on parallel, same features, same performance, different package naming.

So you have two choices:

  • Continue using Tomcat 10, while changing your import statements to use jakarta.* package naming.
  • Switch to using Tomcat 9, while keeping your import statements to javax.*.

If your project is new and greenfield, or small and simple, then I recommend the first. That way you are future-ready. There is no downside other than remembering to adjust the package naming whenever copy-pasting code or reading older articles.

Another benefit is that the latest versions of the Jakarta EE implementations are built to support Java 11 (required) and support Java 17 (optional, but generally done). For this, choose Tomcat 10.1.x rather than 10.0.x. See Tomcat documentation, Which Tomcat?.

If your project is existing, and large, then you may want to put off the chore of transitioning. In this case, stick with Tomcat 9. I suspect you will eventually want to transition, but you may defer for a few years.

By the way, the equivalent competitor to Tomcat, Eclipse Jetty, has chosen the same approach. Jetty development is being done in two parallel versions with same features, same performance, different package naming.


Now is a bit of a confusing time during this Oracle-to-Eclipse transition. To help you get oriented, you can watch any of many video presentations on YouTube, etc. including some published by the Jakarta EE project itself.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
  • but how about <%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core " %>, to what should i change it? – yahyaBdd Jan 21 '22 at 21:32
  • @yahyaBdd I do not know the details there, as I am not a JSTL user. If you want to go with Jakarta, then start with the spec page, [*Jakarta Standard Tag Library*](https://jakarta.ee/specifications/tags/). Then do some queries on a search engine for the new name. And search the Tomcat mailing lists. Tip: The Jakarta community is trying to avoid the compressed abbreviations such as "JSTL" as being too obscure, preferring the full name such as "Jakarta Standard Tag Library". – Basil Bourque Jan 21 '22 at 21:37
  • 1
    thanks for your time that was really helpful, the new packages are jakarta.servlet.jsp.jstl-2.0.0.jar and jakarta.servlet.jsp.jstl-api-2.0.0. Don't need to change the tag library descriptor – yahyaBdd Jan 21 '22 at 22:03
  • @yahyaBdd Looking at [this Answer](https://stackoverflow.com/a/4928309/642706), it seems that Tomcat does not include any API nor implementation for JSTL. So you need to add the API for [Jakarta Standard Tag Library 2.0](https://jakarta.ee/specifications/tags/2.0/), and an implementation. For the implementation, at least one is available, from the Glassfish project, with a link available on that Jakarta.ee spec page. By the way Tag Library 3 is under development as part of Jakarta EE 10, for release later this year, but not yet ready to try. – Basil Bourque Jan 21 '22 at 22:05
  • @yahyaBdd **Update:** [*Jakarta Standard Tag Library 3.0*](https://jakarta.ee/specifications/tags/3.0/) has been released, as part of Jakarta EE 10. – Basil Bourque Jun 11 '22 at 22:24
1

I suggest you to use Maven to make easier adding dependencies or in future if you want to switch from your personal computer to other you should need to copy/paste the external libraries.


To solve your problem if you don't use maven:

  1. Be sure that your libraries are in WebContent -> WEB-INF -> lib folder.
  2. There is newer version of JSTL 2.0 try to switch to it. For this you will need these files:
    • jakarta.servlet.jsp.jstl-2.0.0.jar (this is the JSTL 2.0 implementation of EE4J).
    • jakarta.servlet.jsp.jstl-api-2.0.0.jar (this is the JSTL 2.0 API).

But be carefull 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.