JavaRanch Home    
 
This page:         last edited 27 July 2011         What's Changed?         Edit

Set up JSTL for JSP 2.x   

Servlets 2.5, JSP 2.1, JSTL 1.2

  1. Make sure that your container is Servlets 2.5 and JSP 2.1 capable. For Tomcat that's version 6.
  2. Be sure that your web.xml is properly configured for Servlets 2.5 as described in ServletsWebXml.
  3. Download the JSTL 1.2 jar files. A link to the Sun implementation is available in JstlTagLibDefinitions.
  4. Place the jars in the WEB-INF/lib folder of your web application, or to share them among all apps whatever folder your container uses for such sharing. For Tomcat 6 that would be $CATALINA_HOME/lib. (Please note that sharing these jars across different applications in the same container causes many issues. Because of that it's advised to use them inside the WEB-INF/lib folder of the web application).
  5. In your JSPs be sure to declare the taglibs using the proper URIs. See list below.
  6. If you have a JSP prelude declared in your web.xml, that's a great place to put the taglib declarations as opposed to declaring them on each page.

JSTL 1.2 URIs:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

Servlets 2.4, JSP 2.0, JSTL 1.1

  1. Make sure that your container is Servlets 2.4 and JSP 2.0 capable. For Tomcat that's version 5.0 or 5.5, and for Resin it's version 3.0. JBoss uses Tomcat so check which Tomcat version your JBoss installation is using.
  2. Be sure that your web.xml is properly configured for Servlets 2.4 as described in ServletsWebXml.
  3. Download the JSTL 1.1 jar files. There are two: jstl.jar and standard.jar. You need both! Links available in JstlTagLibDefinitions.
  4. Place the jars in the WEB-INF/lib folder of your web application, or to share them among all apps whatever folder your container uses for such sharing. For Tomcat 5.5 that would be $CATALINA_HOME/shared/lib. (Please note that sharing these jars across different applications in the same container causes many issues. Because of that it's advised to use them inside the WEB-INF/lib folder of the web application).
  5. In your JSPs be sure to declare the taglibs using the proper URIs. See list below. Note that the URIs for JSTL 1.0 and JSTL 1.1 are different. Don't confuse them!
  6. If you have a JSP prelude declared in your web.xml, that's a great place to put the taglib declarations as opposed to declaring them on each page.

JSTL 1.1 URIs:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>


JspFaq JstlTagLibDefinitions

JavaRanchContact us — Copyright © 1998-2014 Paul Wheaton