【问题标题】:No tag "foreach" defined in tag library imported with prefix "c"以前缀“c”导入的标签库中没有定义标签“foreach”
【发布时间】:2012-06-28 02:09:52
【问题描述】:

我正在开发一个应用程序(在 Eclipse 上),在 Tomcat 上带有一些 jsp 页面。

我已经下载了 JSTL jar

(http://jstl.java.net/download.html) 

并将它们添加到 web-inf/lib 和我的构建路径。

但是,当我访问该页面时,我总是得到:

SEVERE: Servlet.service() for servlet [jsp] in context with path [/AccessControl2] threw exception [/ADAccess.jsp (line: 16, column: 1) No tag "foreach" defined in tag library imported with prefix "c"] with root cause

org.apache.jasper.JasperException: /ADAccess.jsp (line: 16, column: 1) No tag "foreach" defined in tag library imported with prefix "c"

这是我的 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

至于我的 JSP,我就是这样做的:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   "http://www.w3.org/TR/html4/loose.dtd">

<HTML>
<BODY>
<script type="text/javascript" src="saveOptions.js"></script>
<FORM METHOD=POST ACTION="SaveADAccess.jsp">

<jsp:useBean id="obj" class="nbsi.config.access.ADGroupListBean" scope="page"/>

<select name="withoutAccess" size="5">

<c:foreach var="item" items="${obj.withoutAccess}">
    <option>${item}</option>
    </c:foreach>
</select>

<select name="withAccess" size="5">

</select>
<P>
        <INPUT TYPE=SUBMIT> 
    <input type="button" onClick="removeOptions(withoutAccess,withAccess)"value="Give Access" />
        <input type="button" onClick="removeOptions(withAccess,withoutAccess)"value="Remove Access" />
</FORM>
</BODY>
</HTML>

我已经搜索过这个问题,但解决方案对我不起作用。

【问题讨论】:

  • 使用forEach,而不是foreach
  • 不错,@GrzegorzGrzybek,您应该将其添加为答案
  • 哇!!太晚了!有人做到了!
  • 那是校对而不是回答;)
  • 这是正确的解决方案。谢谢

标签: jsp foreach jstl taglib


【解决方案1】:

参考下面的链接, https://springbootmvc.blogspot.com/2020/06/jstl-core-tag.html

确保要添加的标题正确,

【讨论】:

    【解决方案2】:

    我认为标记名区分大小写。使用&lt;c:forEach 代替&lt;c:foreach

    【讨论】:

      猜你喜欢
      • 2014-04-09
      • 2012-05-13
      • 2017-03-09
      • 2011-03-13
      • 2019-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多