3


I'm doing a java web application for a coursework, and it is required the use of JSTL library;
so my questions are:
does JSTL need to be configured on tomcat web.xml? If so, how can I configure it?
I have already downloaded the jar file; where do I have to put it?

Thanks in advance!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
DamianFox
  • 902
  • 3
  • 20
  • 45

4 Answers4

4

no, you don't have to define it in web.xml.

You should put the jar into your WEB-INF/lib and declare it in your jsp. something like:

<%@ taglib prefix="c"       uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt"     uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn"      uri="http://java.sun.com/jsp/jstl/functions" %>
Kent
  • 189,393
  • 32
  • 233
  • 301
  • 1
    it gives me this error: 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. – DamianFox Jan 09 '13 at 13:48
  • @DamianFox Do you use jstl 1.0? can you try remove the `/jsp/` from the uri, see if it work – Kent Jan 09 '13 at 13:54
  • 1
    When I remove that part of uri, it gives the same error. Besides I am also using jstl 1.2 – DamianFox Jan 09 '13 at 16:21
  • 1
    Damian, then the JAR is not in `/WEB-INF/lib`, or you have the wrong JAR, or the classpath is a mess (clashes between multiple different JSTL versions). See also http://stackoverflow.com/tags/jstl/info to learn how to install it. – BalusC Jan 09 '13 at 21:53
  • I have downloaded jstl 1.2 again and I have also corrected the uri using the one that is written above.. It works now! Thanks! – DamianFox Jan 10 '13 at 09:23
1

No you need not configure anything in web.xml.

For Java EE 5 containers > You don't have to bundle jstl jars in WEB-INF/lib

Others You have to bundle jstl inside WEB-INF/lib

And use the JSTL tags in JSP by defining the taglib directive like this:

Core Tags

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

Formatting Tags

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

SQL Tags

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

XML Tags

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

Function Tags

<%@ taglib prefix="fn" 
           uri="http://java.sun.com/jsp/jstl/functions" %>
Ramesh PVK
  • 15,200
  • 2
  • 46
  • 50
  • I have tried not to bundle jstl jars in WEB-INF/lib, but Netbeans gives me error, saying that it can't find the jar file.. – DamianFox Jan 09 '13 at 13:53
  • 2
    The part about whether or not to bundle JSTL depending on servlet API version is complete nonsense. It depends on the servlet implementation itself. E.g. Tomcat doesn't ship with JSTL bundled and this is regardless of Tomcat/Servlet version. Please read our JSTL wiki page: http://stackoverflow.com/tags/jstl/info – BalusC Jan 09 '13 at 21:51
  • @BalusC Edited my answer. My intention was to say some containers ship by JSTL by default. And, i have put it in a wrong way. – Ramesh PVK Jan 10 '13 at 04:59
  • I put the jar file within WEB-INF/lib, and now it works! Thanks for your help! – DamianFox Jan 10 '13 at 09:26
  • It is still not true that it depends on whether the container is a Java EE 5 one. JSTL is not bundled in JSP/Servlet containers like Jetty and Tomcat. But JSTL is bundled in full/web profile Java EE containers like Glassfish and JBoss AS. This all is regardless of the version. – BalusC Jan 10 '13 at 11:42
  • @BalusC If i am not wrong. Tomcat and Jetty are not Java EE compliance containers. They are just servlet containers. – Ramesh PVK Jan 10 '13 at 11:55
1

The use of JSTL does not NEED to be configured in web.xml BUT provided you have the jstl-1.x.jar into /WEB-INF/lib, it can be done this way :

in /WEB-INF/web.xml add under <\welcome-file-list>:

  <jsp-config>
    <jsp-property-group>
      <url-pattern>*.jsp</url-pattern>
      <include-prelude>/WEB-INF/taglibs.jsp</include-prelude>
    </jsp-property-group>
  </jsp-config>

Then in /WEB-INF/ create the taglibs.jsp with the following reference

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

With this solution you do not have to add the taglib directive in every single JSP file.

showdev
  • 28,454
  • 37
  • 55
  • 73
Fabrizzio
  • 11
  • 1
-1

You need to make sure jstl-api 1.2 and jstl-impl 1.2 in thw wen-inf/lib directory.No other change in web.xml is necessary.This should work.