JSTL c:forEach在JSP页面上不工作 [英] JSTL c:forEach on JSP page does not work

查看:552
本文介绍了JSTL c:forEach在JSP页面上不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力在我的代码中找到问题,我只是看不到它。

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

在我的servlet中,我创建了一个国家列表,设置为我的请求:

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);

当我调试我的servlet时,我看到国家列表被创建并放入请求。

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

接下来,在我的JSP中,我得到国家列表,迭代它并显示在下拉列表中的值:

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>

当我调试这个,我可以看到countryList在我的请求,但是,我没有在下拉列表中。当我查看我的页面的源代码(在Eclipse中),我看到以下:

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.

有没有任何建议?

提前感谢!

推荐答案

JSTL标签出现在HTML源代码,这是不对的。它应该在服务器端运行,并在HTML输出中完全消失。如果您没有在JSP顶部声明taglib,就会发生这种情况。将以下行添加到JSP的顶部以使JSTL核心标记运行:

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" %>

如果这反过来导致投诉服务器日志中缺少TLD URI,以确保您已安装 JSTL 。也许你正在运行一个不带JSTL内置函数的容器,例如Tomcat或Jetty。

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.

这篇关于JSTL c:forEach在JSP页面上不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆