19 December 2010

Adding JSTL/JSP EL to your web applicaton (updated)

Quite some environments do not come with JSTL: Eclipse for JEE (Galileo), Tomcat 6, Jetty 6... Follow these steps to add them:

  1. Add JSTL
    Grab the JSTL API (jstl-api.jar) and JSTL implementation (jstl-impl-1.2.jar).
    Add the jars to your Container (e.g. Tomcat) lib directory (or your webapp lib).
    Alternatively add them using maven dependencies:
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>
    
  2. Make sure the web-app root element in web.xml supports at least servlet 2.4/JSP 2.0
    <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">
    If you use <taglib> elements in web.xml, make sure they are embedded in a <jsp-config> element.

2 comments:

  1. hey guys. i have JSTL trying to run at JavaEE 6. but with not success. can somebody give a hint. i added the 2 jars at classpath.

    ReplyDelete
  2. Which classpath is that exactly?
    Remark that the post says you should add the jars to the container lib directory or the WEB-INF/lib of your webapp.
    Also in JavaEE6 your web.xml normally refers to servlet 3 - and is not even mandatory anymore.
    If you are a new to this you could use the glassfish application server. It is normally installed with Java EE 6 and it bundles JSTL so you don't need to configure anything.

    ReplyDelete