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

查看:28
本文介绍了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天全站免登陆