What JAR files are needed for Eclipse to use JSTL so it ultimately works on GAE/J?

52,752

Solution 1

Ensure that your web.xml root declaration complies at least Servlet 2.4.

<web-app
    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"
    version="2.4">

    <!-- Config here. -->

</web-app>

Or if your servletcontainer supports it, prefer 2.5:

<web-app 
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">

    <!-- Config here. -->

</web-app>

O if it supports the latest version3.0

<web-app 
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

    <!-- Config here. -->

</web-app>

Otherwise everything will fall back to least supported modus and taglibs may break like that.

Also ensure that you don't have loose tld files wandering around in the classpath (the /WEB-INF/lib folder, among others), they will collide with the ones in JAR files. Oh, also ensure that you didn't manually define the tlds in web.xml, keep it clean.

Solution 2

I had the same issue and I simply put the prefix = "c" at the end of the taglib definition

before:

<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

after:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

And all warnings disappear from Eclipse.

Solution 3

You only need to specify this dependency in your Maven POM:

<dependency>
    <groupId>jstl</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>

In my code, this provided everything I needed for the following JSP taglib to work:

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
Share:
52,752
user45492
Author by

user45492

Updated on April 02, 2020

Comments

  • user45492
    user45492 about 4 years

    I've been trying for longer than I'd like to admit to get JSTL working under Eclipse (and ultimately under GAE/J). I've downloaded Eclipse, the Google App Engine Extension for Eclipse, and JSTL (http://download.java.net/maven/1/jstl/jars/ - jstl-1.2.jar is in the WEB-INF\lib directory).

    My code is below along with the output:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <HTML><HEAD><TITLE>Test Page</TITLE></HEAD><BODY>
    Test Page
    
    <c:set var="myvar" value="3"/>
    
    </BODY></HTML>
    

    The error I get is:

    The tag handler class for "c:set" (org.apache.taglibs.standard.tag.rt.core.SetTag) was not found on the Java Build Path 
    test.jsp
    [my app's path and name]
    line 8
    JSP Problem
    

    From the last post on this page I don't think I need a standard.jar (http://forums.sun.com/thread.jspa?threadID=701267) and in any case I couldn't find one on the Oracle download.java.com site along with the jstl jar.

    EDIT 4: Works now - Steps:
    1) Use the Apache version
    2) Actually include the jar file in the build path (right click the eclipse project and hit Properties -> Java Build Path -> Libraries -> Add Class Folder...; the war/WEB-INF/lib is apparently not on the build path by default)
    3) Add the file c.tld to war/WEB-INF/tld

    Make your web.xml look like:

    <\?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">
    <display-name>JSTLExample</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    <jsp-config>
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
            <taglib-location>/WEB-INF/tld/c.tld</taglib-location>
        </taglib>
    </jsp-config>  
    </web-app>
    

    The test jsp file contents:

     <?xml version="1.0" encoding="UTF-8" ?>
     <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    
     <!-- Taglib -->
     <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     <title>Test Apache ServiceMix with JSTL</title>
     </head>
     <body>
    
     This is a testpage.
    
     <%= "hello" %>
     <c:forEach var="i" begin="1" end="10" step="1">
     <c:out value="${i}" />
    
     <br />
     </c:forEach>
    
    
     </body>
     </html>