How to install JSTL? The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved

13,814

Solution 1

It look like that you're using JSTL 1.0 with taglib URIs of 1.1/1.2. You have JSTL in different versions:

  • 1.0: exist of two JAR files jstl.jar and standard.jar. Taglib URI is has no /jsp in path and library name is suffixed with _rt like http://java.sun.com/jstl/core_rt. Came along and requires at minimum Servlet 2.3 / JSP 1.2. Is end of life, do not use it nowadays.
  • 1.1: exist of same JAR files as 1.0. Taglib URI has no suffix and includes /jsp in the path like http://java.sun.com/jsp/jstl/core. Came along and requires at minimum Servlet 2.4 / JSP 2.0.
  • 1.2: exist of one JAR file jstl-1.2.jar and has same tagtlib URI as 1.1. Came along with Servlet 2.5 / JSP 2.0 but works at Servlet 2.4 / JSP 2.0 as well.

You can find the exact JSTL version by extracting the JAR file with a zip tool and reading the MANIFEST.MF file.

The Servlet/JSP version depends on the webcontainer/application server used (even more, it is a Servlet/JSP implementation) and version level is configureable in web.xml. If you're using at least Servlet 2.5 / JSP 2.0 implementation such as Tomcat 6.0, then I'd recommend to just pick JSTL 1.2. Installing JSTL shouldn't be that hard:

  1. Place the jstl-1.2.jar file in Webapp/WEB-INF/lib. Or when you're using Maven:

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    
  2. Declare the taglib in JSP file with the right TLD URI. You can find here the TLD documentation which applies on both JSTL 1.1 and JSTL 1.2. Click the taglib of interest to get the declaration examples.

Ensure that you have no duplicates of older JSTL versions in the classpath (includes JRE/lib and Appserver/lib) to avoid collisions. If you have full admin-level control over the appserver, then you could also place the JAR file(s) in Appserver/lib instead of Webapp/WEB-INF/lib so that it get applied on all deployed webapps. At least do NOT extract the JAR file(s) and clutter the classpath with its contents (the loose TLD files) and/or declare the taglibs in your webapp's web.xml as some poor online tutorials suggests.

The servlet version declaration in web.xml has also incfluence on functioning of JSTL. Common practice is that you declare it to the highest which your webcontainer/appserver supports. In case of Servlet 3.0, the web.xml should look like:

<?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">
    
    <!-- Config here. -->

</web-app>

Make sure that you don't have a <!DOCTYPE ...> in there, otherwise it will run in Servlet 2.3 compatibility modus and then EL expressions will stop working.

See also:

Solution 2

When declaring a tabglib like you did, the URI is used to uniquely identify each taglib in an internal registry of taglibs, much like a key is used to set/get values from a HashMap or Hashtable in Java.

As per Sun specifications, resolving the URIs to actual tag libraries that can be loaded/called by the application takes place in the following order:

  1. Check the web.xml file for matching taglib tags that have the given URI in them and then follow the taglib-location tag to actually load the TLD.
  2. If no match with #1 was found, recursively check the META-INF directory of all the JARs in the application for TLDs that contain the URI that was specified.

In you case, 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 as indicated by the org.apache.jasper.JasperException so there must be a mismatch somewhere (between the URI and the corresponding JSTL version).

Here, my guess is that you have deployed jstl.jar and standard.jar from JSTL 1.0. To verifiy this, open the file META-INF/c.tld of standard.jar and find the uri element. If what you can read is <uri>http://java.sun.com/jstl/core</uri>, then you've found the issue.

So, to solve the problem, either change your taglib declaration in your JSPs like this:

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

Or (and this this IMHO the preferred solution), upgrade your JSTL version to match the version expected by the JSPs, i.e. use JSTL 1.1. You can download this version from here. Then, just put the jstl.jar and standard.jar in your WEB-INF/lib (if you check META-INF/c.tld in standard.jar, you'll see that it declares the <uri>http://java.sun.com/jsp/jstl/core</uri>).

Solution 3

For reasons which probably seemed like a good idea, the "inventors" of JSTL changed the URL between versions 2.2 and 2.3 (I think). I've cursed about this on several occasions.

For a first approximation, you could try removing the "jsp" from the URI cited.

There's more, interesting but confusing, information on this problem here: http://forums.sun.com/thread.jspa?threadID=486791

Share:
13,814
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    This is my JSP page's taglib directive:

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


    I'm getting the following ERROR :

    HTTP Status 500 - 
    --------------------------------------------------------------------------------
    type Exception report
    message 
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception 
    org.apache.jasper.JasperException: 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
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:51)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:116)
    org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:315)
    org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:148)
    org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:420)
    org.apache.jasper.compiler.Parser.parseDirective(Parser.java:476)
    org.apache.jasper.compiler.Parser.parseElements(Parser.java:1426)
    org.apache.jasper.compiler.Parser.parse(Parser.java:133)
    org.apache.jasper.compiler.ParserController.doParse(ParserController.java:215)
    org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:167)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    


    I have added the JAR file jstl.jar and standard.jar in the /WEB-INF/lib folder.
    Can anyone tell me where I'm making the mistake?

  • skaffman
    skaffman over 14 years
    This is a URI, not a URL, relative paths don't make sense in this case, and although some containers might allow that, it's non-standard and non-portable.
  • Carl Smotricz
    Carl Smotricz over 14 years
    Awesomely helpful and informative answer! If no other, you have at least my upvote for greatly amplifying on the bit of info I had.