【发布时间】:2013-09-30 19:05:08
【问题描述】:
我有一个带有一些 JSTL 标记的 JSP,除了 forEach 之外,它们都可以正常工作。这是我的 JSP 代码:
header.jsp
<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec"
uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ page isELIgnored="false"%>
<meta charset="utf-8">
<div>
<!-- header stuff -->
</div>
home.jsp
<html>
<head></head>
<body>
<%@include file="header.jsp"%>
<c:if test='${pageContext["request"].userPrincipal.principal.enabled eq false}'>
<div class='alert alert-warn fade in'>
....
</div>
</c:if>
<table>
<c:choose>
<c:when test="${not empty results}">
<c:forEach var="item" items="${results}">
...
</c:forEach>
</c:when>
<c:otherwise>
<tr id="noItems" class="accordion-toggle" >
<td>No items.</td>
</tr>
</c:otherwise>
</c:choose>
</table>
</html>
我看不到任何内容,也看不到结果,也看不到“无项目”消息。
我的依赖如下:
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
在 tomcat 6 上部署它不起作用,但如果我使用 Maven Tomcat 插件在 Eclipse 上部署它,它就可以正常工作。 有谁知道错误可能出在哪里?
编辑:
我在控制台中收到此错误:
[TagLibraryInfoImpl] 属性中的未知元素(延迟值)
【问题讨论】:
-
Tomcat 不提供开箱即用的 JSTL,但您已经告诉 Maven 就是这种情况。换句话说,您已经以某种方式手动安装了它,并且考虑到症状(例如 API/impl 不匹配或重复;错误消息提示您实际上是在使用 JSTL 1.1 impl 和 JSTL 1.2 API),这部分可能是错误的.如果您详细说明您是如何安装 JSTL 的,那么我们可以指出错误。同时,仔细阅读stackoverflow.com/tags/jstl/info
-
@BalusC 我编辑了帖子以显示当前版本。我唯一做的就是将这些依赖项添加到 pom.xml 中。 Tomcat 是全新的。我也在使用 Spring MVC 3.2.1.RELEASE,它是否有可能在任何地方都包含 JSTL 1.1?
-
不知道。提取 Maven 构建的 WAR 文件并检查
/WEB-INF/lib中的 JAR。 -
@BalusC 我查过了,但是没有 JSTL1.1 jar,只有 jstl1.2.jar
-
JSTL 1.1 impl 的文件名(相当混乱)
standard.jar。你也专门找过这个吗?