6

JSTL variable values are not shown in EL. For example this code:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<html>
<body>
  <c:forEach var="i" begin="1" end="5" >
    <c:out value="${i}" /> 
  </c:forEach>
</body>
</html>

browser renders like: ${i} ${i} ${i} ${i} ${i}

Or this one:

<c:set var="someVar" value="Hello"/>
<c:out value="${someVar}"/>

browser displays: ${someVar}

I'm using Spring-MVC 3 and Maven to build the sample project, deploying it to Tomcat 7. In Spring's context I have view resolver configurated as follows:

<bean class=
    "org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass" value="
        org.springframework.web.servlet.view.JstlView"></property>
    <property name="prefix" value="/WEB-INF/"></property>
    <property name="suffix" value=".jsp" />
</bean>

Model variables passed form Spring's controller not shown as well.

Mavens pom.xml has following jstl related dependencies:

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

So, any suggestions how to resolve this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
adrift
  • 637
  • 2
  • 10
  • 34

1 Answers1

12

So, the EL (those ${} things) doesn't get executed? That can happen when your servletcontainer runs at Servlet 2.3 / JSP 1.2 modus or lower, while you're using JSTL 1.1 or newer. During the change from JSTL 1.0 to 1.1, EL was moved from JSTL into JSP. That was JSP 2.0, which is part of Servlet 2.4. JSP 1.2 and older doesn't have EL bundled. JSTL 1.1 and newer doesn't have EL bundled.

You need to make sure that your web.xml root declaration conforms at least Servlet 2.4. As you're using JSP 2.1, which is part of Servlet 2.5, you're apparently targeting a Servlet 2.5 compatible container. So, make sure that your web.xml root declaration conforms Servlet 2.5:

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

    <!-- Config here. -->

</web-app>

Tomcat 7 is however a Servlet 3.0 compatible container. I'd consider changing maven pom to declare Servlet 3.0 / JSP 2.2 so that you can benefit all the new Servlet 3.0 features.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you very much! This declaration helped. Does this mean I should not care about any jstl related jars in lib since I'm using Servlet 2.5 compatible web container? – adrift Mar 13 '12 at 00:34
  • Depends on the target container. Tomcat for example doesn't ship with JSTL. So you still need JSTL JARs. See also the "Our JSTL wiki page" link. Note that Tomcat 7 is Servlet 3.0 compatible. But you've JSP 2.1 instead of JSP 2.2 in your maven pom, so perhaps you're actually targeting a Servlet 2.5 production environment. – BalusC Mar 13 '12 at 00:35