47

I wrote a web application with Eclipse Tomcat and it works on my local Tomcat 7, when I tried to publish it online on a Tomcat 7, I had the following error:

SEVERE: Servlet.service() for servlet [obliquid.servlet.Index] in context with path [/cp] threw exception [The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application]

Tomcat 7 has "Spec versions: Servlet 3.0, JSP 2.2, EL 2.2", so JSTL is not included?

When I tried to upload standard.jar and jstl.jar I had the following error:

org.apache.jasper.JasperException: /jsp/index.jsp (line: 3, column: 62) Unable to read TLD "META-INF/c.tld" from JAR file "jndi:/localhost/cp/WEB-INF/lib/standard.jar": org.apache.jasper.JasperException: Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV

I did some googling, but I couldn't sort it out, some said it could be caused by conflicting versions of the jars. Maybe I should not include those jars and use a different JSTL url? Mine is for JSTL 1.1 I think, is there a new URL for JSTL 1.2?

What should I do to solve the problem and make this application run?

Jarrod Dixon
  • 15,727
  • 9
  • 60
  • 72
stivlo
  • 83,644
  • 31
  • 142
  • 199
  • Hi Ravi, I will try to post the relevant parts. In the meantime, I went on trying and instead of publishing with rsync (as I've always done before), I published the war, and this time the application worked. Since it needs to stay online, I will not touch this server and setup a new one with the same Tomcat 7.0.14. I will need several minutes... – stivlo May 23 '11 at 08:24
  • 3
    Check our JSTL wiki page: http://stackoverflow.com/tags/jstl/info You can get those kind of pages when hovering the `[tag]` below the question until a box pops up and then clicking the *info* link. – BalusC May 23 '11 at 13:16
  • Thank you BalusC, always helpful, maybe it should be updated with Servlet 3.0 declaration too. – stivlo May 23 '11 at 14:47

9 Answers9

55

I have been fighting with this for several hours. Here is a complete solution.

  1. I am using Tomcat 7, which is a Servlet 3.0-compliant server.

  2. If you desire to use the Servlet 3.0 spec, you must have your web.xml as follows:

    <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"> 
    
  3. If you're using Maven, your pom.xml should have these lines.

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>
    
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>jstl-impl</artifactId>
        <version>1.2</version>
        <exclusions>
            <exclusion>
                <artifactId>servlet-api</artifactId>
                <groupId>javax.servlet</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jsp-api</artifactId>
                <groupId>javax.servlet.jsp</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jstl-api</artifactId>
                <groupId>javax.servlet.jsp.jstl</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    

    These dependencies are very important. JSTL 2.1 + Tomcat 7 + Servlet 3.0 is very broken unless you fix it by using these lines, especially the exclusion part. What is happening is the JSTL 2.1 Jars are actually pulling in the wrong versions of the Servlet spec--2.5. Unless you stop that from happening, you will be in a whole world of pain. A special thanks to Mr. Murray Todd Williams for these insights .

  4. Finally, in case Maven can't find those JARS, you can make Eclipse happy by including three JARS with your project and doing the usual Project--> Properties--> Java Build Path and include them that way--though Maven should take care of it.

    javax.servlet-api-3.0.1.jar
    javax.servlet.jsp.jstl-1.2.1.jar
    javax.servlet.jsp.jstl-api-1.2.1.jar
    
  5. Please note! This exact configuration only applies if you are using the magic combination of:

    1. A Servlet 3.0-compliant application server such as Tomcat 7

    2. Your web.xml has the right namespace for the Servlet 3.0 spec

    3. You have those three JARS and no other JSTL or Servlet JARS on your classpath.

  6. Make sure you do not place copies of these JARs in your WEB-INF/lib directory because they would in that case be sent to the server thereby causing LinkageErrors.

  7. In your JSP, you need to have this PRECISE line, formatted exactly as I have it or else Eclipse will whine that it doesn't recognize the c:blah tags:

    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    
  8. What a danged PITA! This is MUCH harder to implement than any other version of JSTL. This is the only example of something getting much more complicated rather than simpler in later iterations.

Eliran Malka
  • 15,821
  • 6
  • 77
  • 100
Tom Hunter
  • 1,051
  • 7
  • 4
  • 4
    Thanks! I went through this same exact problem... It sucked the hours out my day, thanks for making it known! – Daniel Macias Feb 26 '14 at 05:38
  • 2
    If anyone feels that the solution does not work for them, check that EL is not ignored. Add the below line to your JSP pages. This takes care that EL is not ignored. <%@ page isELIgnored="false" %> – Vishnu Jun 04 '14 at 12:54
  • thank you a lot. best anwser, specially thank for maven config. I have modified it to use with 3.1.0 servlets and it's work like a charm – Oleg Abrazhaev Apr 04 '16 at 15:46
45

Tomcat has never included JSTL.

You should put the jstl and standard jars in WEB-INF/lib (you've done that), and make sure you have the permissions to read them (chmod)

Your URI is correct and it should work (works here)

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • "Tomcat has never included JSTL": thanks, I thought the new Tomcat 7 had it, good to know. It might be a permission problem, now I'm installing again and will check, I will update you, thanks. – stivlo May 23 '11 at 08:30
  • 7
    Ok, so here is the update: I installed everything as it was in the new server and everything works. The difference was that I was rsyncing as the root user before, and now I rsynced as tomcat. I think this should mean it was indeed a permission problem. – stivlo May 23 '11 at 12:11
14

Your uri is correct for JSTL 1.2. You need to do two things :

Change your web.xml to use the latest web-app version.

It should look something like this or a later version;

<?xml version="1.0" encoding="UTF-8"?>
<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">

Secondly put the correct version of jstl jars in your code. For 1.2 You can download them here.

This should give you two jars:

  • jstl-api.jar
  • jstl-impl.jar

Use these, instead of standard.jar and jstl.jar which were for previous version.

Let us know how this works for you.

Eliran Malka
  • 15,821
  • 6
  • 77
  • 100
VikC
  • 389
  • 1
  • 3
  • 9
9

For running on apache tomcat 7 adding these into your POM is probably appropriate. These jars don't reference javax.servlet jars like the glassfish ones do, so there is no need for exclusions.

<dependency>
    <groupId>org.apache.taglibs</groupId>
    <artifactId>taglibs-standard-spec</artifactId>
    <version>1.2.1</version>
</dependency>
<dependency>
    <groupId>org.apache.taglibs</groupId>
    <artifactId>taglibs-standard-impl</artifactId>
    <version>1.2.1</version>
</dependency>
K.Nicholas
  • 10,956
  • 4
  • 46
  • 66
0

For Tomcat, there is a simpler dependency solution for JSTL 1.1.2:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <!-- Apache Taglibs does not implement version 1.2 -->
    <version>1.1.2</version>
  </dependency>
  <dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
    </dependency>
  <dependency>
    <groupId>taglibs</groupId>
    <artifactId>c</artifactId>
    <version>1.1.2</version>
    <type>tld</type>
  </dependency>
  <dependency>
    <groupId>taglibs</groupId>
    <artifactId>fmt</artifactId>
    <version>1.1.2</version>
    <type>tld</type>
  </dependency>
<dependency>

See here for more details (personal blog).

REM: More details as requested, one has to include JSTL dependencies to make them available on Tomcat. Yet, version 1.2 is not really necessary, since version 1.1.2 (delivered by Apache, like Tomcat) does the job too. Its only requirement is Servlet 2.4 and JSP 2.2, and the OP mention Servlet 3.0 and JSP 2.0, which is good enough.

Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
0

There are two answers here that are mostly correct with regard to how to solve this problem when using Maven when dealing with this issue. However, both are not 100% complete.

Using Exclusions per @Tom Hunter's answer

This answer works. However, there will still be log messages from Tomcat regarding duplicate TLD definitions. This is because both the jstl and jstl-impl artifacts include the TLD definitions. To remove those messages, I think a better Maven setup is this:

<dependency>
    <version>1.2</version>
    <scope>runtime</scope>
    <groupId>javax.servlet.jsp.jstl</groupId>
    <artifactId>jstl-api</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>servlet-api</artifactId>
            <groupId>javax.servlet</groupId>
        </exclusion>
        <exclusion>
            <artifactId>jsp-api</artifactId>
            <groupId>javax.servlet.jsp</groupId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>jstl-impl</artifactId>
    <version>1.2</version>
    <scope>runtime</scope>
    <exclusions>
        <exclusion>
            <artifactId>servlet-api</artifactId>
            <groupId>javax.servlet</groupId>
        </exclusion>
        <exclusion>
            <artifactId>jsp-api</artifactId>
            <groupId>javax.servlet.jsp</groupId>
        </exclusion>
        <exclusion>
            <artifactId>jstl-api</artifactId>
            <groupId>javax.servlet.jsp.jstl</groupId>
        </exclusion>
    </exclusions>
</dependency>

This includes only the jstl api classes with the necessary exclusions to avoid the problems explained in the rest of that answer.

Using newer POM versions per @George's answer

It took me a while to realize it, but there are newer versions of the JSTL pom's available. It's really confusing because these newer packages use similar, but slightly different naming conventions. These newer versions mark the javax.servlet, javax.jsp, etc dependencies as provided scope so that they do not need to be excluded. The 1.2.1 version depends on a 1.2.1 version of the jstl-api. And so this would work as well as above answer:

<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>javax.servlet.jsp.jstl</artifactId>
    <version>1.2.1</version>
    <scope>runtime</scope>
</dependency>

This differs slightly from George's answer because I changed scope to runtime. George specified scope as provided. With a provided scope, the jars would have to be copied manually in to the Tomcat lib directory, or some other dependency would have to included the necessary implementation.

However, I could not find the 1.2.1 version of the impl in maven central, jboss repo, or any other repos. I ended up going around in circles and finally just used a local file based repo to store the jar. The dependency and jar are described here:

Community
  • 1
  • 1
kaliatech
  • 17,579
  • 5
  • 72
  • 84
0

None of these worked for me, I simply created the project without using Maven and adding the JAR files directly.

Pablo Gonzalez
  • 1,710
  • 3
  • 21
  • 36
-1

I suffered from the error: SEVERE: Servlet.service() for servlet [obliquid.servlet.Index] in context with path [/cp] threw exception [The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application] on Tomcat 7

The Solution: copy jars jstl-1.2.jar and javax.servlet.jsp.jstl-api-1.2.1.jar straight to Tomcat Library Directory. Redeploy Tomcat Library in Eclipse again.

Tomasz
  • 19
  • 4
-1

The following dependencies in the pom.xml seem to resolve the issue:

<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>javax.servlet.jsp.jstl</artifactId>
    <version>1.2.1</version>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>javax.servlet.jsp.jstl</groupId>
    <artifactId>javax.servlet.jsp.jstl-api</artifactId>
    <version>1.2.1</version>
    <scope>provided</scope>
</dependency>

That was a strange combination - two different groupIds - but it does work :). My expectation was to see the same group ID for both jars. I managed to redeploy without a problem to Tomcat 7.

Also, if you see "Unkown tag

George
  • 84
  • 1
  • 2