JSTL tags on JSP page do not work and appear plain in HTML page source

I've been struggling to find the problem in my code and I just don't see it.

In my servlet, I create a list of countries and set it into my request:

List<Country> countryList = (new CountryListForm(countryDAO)).getList();
request.setAttribute(ATTRIBUTE_COUNTRY_LIST, countryList);

When I debug my servlet, I see that the list of countries is created and placed into the request.

Next, in my JSP, I get the country list, iterate through it and display the values in a drop-down list:

        <select id="clubCountryId" name="clubCountryId">
            <c:forEach var="country" items="${countryList}">
                <option value="${country.id}">
                    ${fn:escapeXml(country.name)}
                </option>
            </c:forEach>
        </select>

When I debug this, I can see that the countryList is in my request and the countries are present. However, I get nothing in my drop-down list. When I view the source of my page (in Eclipse), I see the following:

        <select id="clubCountryId" name="clubCountryId">
            <c:forEach var="country" items="[eu.ctt.pojo.Country@c7057c, eu.ctt.pojo.Country@391da0, eu.ctt.pojo.Country@1c7f37d, eu.ctt.pojo.Country@42a6eb, eu.ctt.pojo.Country@1dcc4cd]">
                <option value="">

                </option>
            </c:forEach>
        </select>

As you can see, my five objects are present but it just doesn't want to iterate over them. I have other pages where I basically do the same thing (list of countries but not in a drop-down) and I have no problem.

Does anyone have any suggestions?

Thanks in advance!


Solution 1:

The JSTL tags appear in the HTML source, this is not right. It is supposed to run in the server side, and disappear completely in the HTML output. This can happen if you didn't declare the taglib in top of JSP. Add the following line to the top of your JSP to get the JSTL core tags to run:

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

If this in turn results in a complaint of a missing TLD URI in the server logs, then you need to ensure that you've installed JSTL. Perhaps you're running a container which doesn't ship with JSTL builtin, such as Tomcat or Jetty.

See also:

  • Enabling JavaServerPages Standard Tag Library (JSTL) in JSP