JSP页面上的JSTL标记不起作用,并在HTML页面源代码中清晰显示 [英] JSTL tags on JSP page do not work and appear plain in HTML page source

查看:152
本文介绍了JSP页面上的JSTL标记不起作用,并在HTML页面源代码中清晰显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力在代码中找到问题,但我只是没有看到它.

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.

这篇关于JSP页面上的JSTL标记不起作用,并在HTML页面源代码中清晰显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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