我正在使用Tomcat上的一些jsp页面开发一个应用程序(在Eclipse上)。
我已经下载了JSTL罐子
(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>
我已经搜索过这个问题了,但解决方案对我没用。
答案 0 :(得分:15)
我认为标记名区分大小写。请使用<c:forEach
代替<c:foreach
。
答案 1 :(得分:-2)
请参考以下链接, https://springbootmvc.blogspot.com/2020/06/jstl-core-tag.html
确保要添加的标题正确, <%@ taglib uri =“ http://java.sun.com/jsp/jstl/core”前缀=“ c”%>