facebook

Getting JSTL core library working

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #244670 Reply

    mwunderlich
    Member

    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>

    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”%&gt;

    <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&#8221;
    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
    xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”&gt;

    </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,

    “c.tld” is in 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?
    I am using Tomcat 5.5.4, Eclipse 3.1.1. and MyEclipse 4.0.3. I have tried setting up new projects with both JSTL 1.0 and 1.1. I even tried manually removing all libraries and tld’s and leaving only standard.jar and jstl.jar in the web-inf/lib directory.

    Cheers,

    Martin

    #244682 Reply

    Riyad Kalla
    Member

    Martin,
    Tag is part of the jsp-2.0 spec. In Tomcat this is in the common/lib/jsp-api.jar file. If you check your build path do you have the J2EE 1.4 Library added to your build path? It should include this file.

    #244687 Reply

    mwunderlich
    Member

    Thanks a lot for the reply! I should have mentioned that I checked for jsp-api before. The library jsp-api.jar is there alright in the directory common/lib of my Tomcat folder. In addition, I just tried importing j2ee.jar as an external library. It is listed in the project preference’s build path, but no success.

    I hope to get this sorted soon, because I am stuck on a project where I had planned to use JSTL.

    Cheers,

    Martin [/quote]

    #244688 Reply

    mwunderlich
    Member

    Thanks a lot for the reply! I should have mentioned that I checked for jsp-api before. The library jsp-api.jar is there alright in the directory common/lib of my Tomcat folder. In addition, I just tried importing j2ee.jar as an external library. It is listed in the project preference’s build path, but no success.

    I hope to get this sorted soon, because I am stuck on a project where I had planned to use JSTL.

    Cheers,

    Martin [/quote]

    #244695 Reply

    Riyad Kalla
    Member

    Martin,
    The problem is that the JAR that contains the required class is not in your build path so Eclipse cannot find it. You can either add jsp-api.jar and servlet-api.jar to your project’s build path as External JARs, or make sure that the J2EE 1.4 Library is in your path.

    #244710 Reply

    mwunderlich
    Member

    The J2ee library is there on the build path. Just to make sure, I also explicitly added jsp-api and servlet-api to the build path. I can see the missing Tag class in the eclipse project. It’s still not working. Any other ideas?

    Cheers,

    Martin

    #244711 Reply

    Riyad Kalla
    Member

    Are you getting this exception during runtime or during build time of the app?

    #244716 Reply

    mwunderlich
    Member

    During run time, when I try to access the JSP on the localhost.

    #244719 Reply

    Riyad Kalla
    Member

    Ahh I thought you were getting this at build time. If you are getting this at run time, check your deployed apps WEB-INF/lib dir. Make sure NO jsp-api.jar or servlet-api.jar OR j2ee.jar JARs are in there. Your app server provides those for you.

    Now go into your common/lib dir and confirm that jsp-api and servlet-api.jar are both there. Now double check that you are deploying your app to Tomcat 5 and not Tomcat 4, Tomcat 4 won’t have these files, but 5 will.

    #244738 Reply

    mwunderlich
    Member

    It’s working now! Brilliant, what a relieve. I can’t really say what the problem was. When I checked again this morning for those jar files, according to your advice, all I could find in web-inf/lib were jstl.jar and standard.jar. In Tomcat’s common/lib I found jsp-api-jar and servlet-api.jar alright. However, when I tried to access the jsp again, I got a different error:

    “org.apache.jasper.JasperException: /index.jsp(7,4) According to TLD or attribute directive in tag file, attribute value does not accept any expressions”

    I was able to fix this by changing my URI from
    <%@ taglib prefix=”c” uri=”http://java.sun.com/jstl/core”%&gt;
    to
    <%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core”%&gt;.

    Right so, I am off coding away now – until the next time it grinds to a halt. 🙂 (Is it just me or is it always like that – moving from one block to the next?)

    Cheers,

    Martin

    #244748 Reply

    Riyad Kalla
    Member

    Glad it’s working now Martin.

    (Is it just me or is it always like that – moving from one block to the next?)

    It certainly feels like that, but I would say that only lasts a few weeks before you come to recognize all the errors and what they mean. For example, your problem above “According to TLD or attribute directive…” in another thread had a user stumped for 1 week, but you knew what the problem was right away. The trick is learning all the hickups 🙂

Viewing 11 posts - 1 through 11 (of 11 total)
Reply To: Getting JSTL core library working

You must be logged in to post in the forum log in