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.
CodePudding user response:
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:
- Be sure that your libraries are in WebContent -> WEB-INF -> lib folder.
- 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.
CodePudding user response:
Study that first line of error message. On the left, notice jakarta.. On the right, notice javax..
Java EE ➠ Jakarta 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
importstatements to usejakarta.*package naming. - Switch to using Tomcat 9, while keeping your
importstatements tojavax.*.
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.
