jsp - JSTL 语句出现在生成的 HTML 中的错误位置和格式
问题描述
我正在尝试生成从 Java 应用程序调用的通用列表页面。在 myApp.java 中,我创建/分配了三个请求属性:
List<String> columnTitles = myClass.getColumnTitles ();
request.setAttribute ("columnTitles", columnTitles);
request.setAttribute ("columnCount", columnTitles.size ());
List<List<String>> MyList = myClass.getList ();
request.setAttribute ("columns", MyList);
RequestDispatcher rd = request.getRequestDispatcher ("myListPage.jsp");
rd.forward (request, response);
在文件“myListPage.jsp”中,我有:
<%@ page import="java.util.List"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div class="myTableBody">
<p>Column count = <%= request.getAttribute ("columnCount") %></p> <!-- temp -->
<table class="myTableClass">
<thead>
<tr>
<c:forEach items="${columnTitles}" var="columnName">
<th>${columnName}</th>
</c:forEach>
</tr>
</thead>
不幸的是,会生成如下内容:
<div class="myTableBody">
<p>Column count = 6</p> <!-- temp -->
<c:foreach items="[id, name, type, url, telephone, mobile]" var="columnName">
</c:foreach><table class="myTableClass">
<thead>
<tr>
<th></th>
</tr>
</thead>
<c:foreach ...></c:foreach> 循环超出了标签的范围,更不用说标签了。显示列数,但不显示列标题或列本身。
该项目在 Apache Tomcat 8.0.21 下运行。我已经加载了 JSTL 1.2。在项目的 web.xml 文件中,web-app 版本为“2.5”。
在我必须编写自己的脚本之前有什么帮助(这是不好的做法)?
解决方案
推荐阅读
- python-3.x - 错误:没有为 ipython==7.18.1 找到匹配的分布
- entity-framework-core - 在 Firebird 2.5 EF Core 上定义“一对一”关系
- unit-testing - 为什么在 Angular 10 单元测试中没有将 FormControl 标记为脏?
- javascript - 如何使用 react-pdf 进行自动换行
- assembly - 为 arm32 构建 GLIB 时,asm 中的输出约束“=d”无效(Windows)
- google-apps-script - 需要帮助使用 Google Apps 脚本构建 Telegram 网络应用程序
- selenium-webdriver - @FindBy 使用 xpath 与 linkText
- python - psycopg2 错误:在行号上的字符串格式化期间并非所有参数都转换:执行 SELECT 计数语句时为 46
- node.js - 我可以让 Passport.js 向新注册帐户添加新字段吗?
- c# - 如何在 C# 中停止进一步处理全局热键