Getting JSTL core library working
Dear all,
I have problems getting the basic JSTL core library working. I have searched the forum archives and the web, but to no avail.
My JSP page looks like this:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<body>
<c:forEach var="i" begin="1" end="10" step="1">
<c:out value="${i}" />
</c:forEach>
</body>
</html>
My web-xml is this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
</web-app>
I am using Tomcat 5 and JSTL 1.1. "c.tld" is my web-inf directory and the two libraries jstl.jar and standard.jar are in "web-inf/lib".
So, everything should be fine - in theory. However, I keep getting the following error:
java.lang.NoClassDefFoundError: javax/servlet/jsp/tagext/Tag
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:620)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
java.net.URLClassLoader.access$100(URLClassLoader.java:56)
java.net.URLClassLoader$1.run(URLClassLoader.java:195)
java.security.AccessController.doPrivileged(Native Method)
[etc.]
So, it seems like the tag can't be found. Any ideas why that is?
Cheers,
N.
[2204 byte] By [
NetWundia] at [2007-10-2 9:46:58]

Your setup/config for JSTL seems ok for the most part.
You shouldn't need c.tld anywhere in the WEB-INF directory.
It is already encapsulated in standard.jar.
All you need to run JSTL are the jar files in the WEB-INF/lib directory. Anything else is unnecessary extra, and can actually hurt rather than help.
>java.lang.NoClassDefFoundError: javax/servlet/jsp/tagext/Tag
The class not found is a standard part of the JSP/Servlet API - not actually part of JSTL. The class should already be present via the jsp-api.jar file in [TOMCAT]/common/lib directory.
Sometimes the "classNotFound" error occurs if the class appears twice in the classpath.
Have you got any other jar files in your web-inf/lib directory that might conflict with this? maybe j2ee.jar?
You should NOT have servlet.jar, servlet-api.jar, jsp-api.jar or ANY jar file that has the jsp/servlet classes in your WEB-INF/lib directory, as they confuse the container.
Also check the /shared/lib directory
Maybe try it from scratch with a completely new web app.
Put ONLY jstl.jar and standard.jar in the WEB-INF/lib directory
Hopt this helps,
evnafets
Thanks a lot for your detailed reply!!
> You shouldn't need c.tld anywhere in the WEB-INF
> directory.
I should have clarified this in my firt post: I am using MyEclipse for creating the web application. When setting up the project, it has two options for including either JSTL 1.0 or 1.1. By using one of these options the tld files will be included.
However, I removed those manually from the webroot folder.
> >java.lang.NoClassDefFoundError:
> javax/servlet/jsp/tagext/Tag
> The class not found is a standard part of the
> JSP/Servlet API - not actually part of JSTL. The
> class should already be present via the jsp-api.jar
> file in [TOMCAT]/common/lib directory.
> Sometimes the "classNotFound" error occurs if the
> class appears twice in the classpath.
I checked the project build path. jsp-api.jar is not there. It is, however, contained in the common/lib directory of Tomcat.
>
> Have you got any other jar files in your web-inf/lib
> directory that might conflict with this? maybe
> j2ee.jar?
No, nothing there except standard.jar and jstl.jar.
> You should NOT have servlet.jar, servlet-api.jar,
> jsp-api.jar or ANY jar file that has the jsp/servlet
> classes in your WEB-INF/lib directory, as they
> confuse the container.
> Also check the /shared/lib directory
Nothing in there.
> Maybe try it from scratch with a completely new web
> app.
> Put ONLY jstl.jar and standard.jar in the WEB-INF/lib
> directory
Just tried from scratch, but not success.
Has anyone around here managed to create a simple JSTL app with MyEclipse?
Cheers,
N.
>
> Hopt this helps,
> evnafets
add these lines in your web.xml befor closing </web-app>
I think it will solve your problem
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/tld/fmt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt-rt</taglib-uri>
<taglib-location>/WEB-INF/tld/fmt-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tld/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core-rt</taglib-uri>
<taglib-location>/WEB-INF/tld/c-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
<taglib-location>/WEB-INF/tld/sql.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/sql-rt</taglib-uri>
<taglib-location>/WEB-INF/tld/sql-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
<taglib-location>/WEB-INF/tld/x.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/x-rt</taglib-uri>
<taglib-location>/WEB-INF/x-rt.tld</taglib-location>
</taglib>
after WEB-INF the tld is folder which i created through build.xml if you wish don't create a folder
>add these lines in your web.xml befor closing </web-app>
[SNIP]
No, don't do that. It is completely unnecessary.
The tlds for the taglibs are bundled in the META-INF directory of standard.jar. The URI for each taglib is coded into that tld.
What this means is that as long as you import using the standard URI, then the container will find the descriptor bundled in the jar file.
JSTL1.0 <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
JSTL1.1 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
Specifying taglib tags in the web.xml is the old way of doing things. Embrace the new and improved!
NetWundi,
I think I have a similar problem to yours though I'm using BEA as our server and Eclipse as the IDE. Don't know if Eclipse and MyEclipse are similar.I was able to get a custom tag test to work - except for the datasource which I'm still trying to work out.I was getting an error about the TAGLIB not being found. I had to open the Properties dialog of my Dynamic Web Project, select the J2EE Module Dependencies and add the standard.jar and jstl.jar as external jars.
I don't know if this will help but thought I would post it.
Jim
jrda at 2007-7-16 23:52:22 >
