I am just learning JSP and am testing using JSTL on Tomcat 7. I am able to successfully define and use custom tags. But when I attempt to implement JSTL the container throws two exceptions. How can I fix this so the jsp will translate properly?
java.lang.ClassNotFoundException: javax.servlet.jsp.tagext.TagLibraryValidator
java.lang.NoClassDefFoundError: javax/servlet/jsp/tagext/TagLibraryValidator
I’m using the following jar files.
javax.servlet.jsp.jstl-1.2.1.jar
javax.servlet.jsp.jstl-api-1.2.1.jar
I have placed the two JSTL 1.2.1 jars in WEB-INF/lib of the test web app and the CLASSPATH for my JRE. I have also marked the two jars for export in the build path options in Eclipse.
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<c:out value="JSTL works."></c:out>
</body>
</html>
This class is part of JSP 2.0. Tomcat is a Servlet 3.0 / JSP 2.2 container. Make sure that your
web.xmlis declared conform Servlet 3.0.And also that you don’t have arbitrary JAR files of a different container make/version like
jsp-api.jarfrom Tomcat 5.5 or so in your/WEB-INF/lib. It would otherwise only conflict. See also How do I import the javax.servlet API in my Eclipse project?That should be sufficient. If cleaning the
web.xmland the classpath still doesn’t fix the problem, perhaps you don’t have the right JARs at all. In our JSTL wiki page you can find a download link to a single jstl-1.2.jar file. Drop it in/WEB-INF/liband remove the other JARs.Please don’t do that. Just dropping the JSTL JAR in
/WEB-INF/libis sufficient. Also make sure that you don’t drop arbitrary servletcontainer-specific JARs in yourJRE/liborJRE/lib/ext. Just don’t touch those folders. Webapp-specific libraries should go in/WEB-INF/lib. If you’re using an IDE, it will then do automatically all the necessary magic. You don’t even need to fiddle in buildpath properties. TheCLASSPATHenvironment variable is only used when you runjavacommand in your command console and even then only when you run it without the-cp,-classpathand-jararguments.