java未知标记(c:foreach)。日蚀
我有jstl代码,它是由maven well构建的。。。但是Eclipse有编译错误“未知标记(c:foreach)”
代码如下:
<%@ 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>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<ul>
<c:forEach items="${listOfMyFriends}" var="friend">
<c:out value="${friend}"></c:out>
</c:forEach>
</ul>
</body>
</html>
有人能帮我避免这个问题吗
有完整的pom:` http://maven.apache.org/xsd/maven-4.0.0.xsd“>; 4.0.0
<groupId>com.godzevych</groupId>
<artifactId>springInActionMVCTemplate</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>springInActionMVCTemplate</name>
<url>http://maven.apache.org</url>
<properties>
<java.version>1.6</java.version>
<spring.version>3.1.0.RELEASE</spring.version>
<cglib.version>2.2.2</cglib.version>
</properties>
<dependencies>
<!-- Spring core & mvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<!-- CGLib for @Configuration -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>${cglib.version}</version>
<scope>runtime</scope>
</dependency>
<!-- Servlet Spec -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<!-- JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
<!-- JSR 330 -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>springsource-milestones</id>
<name>SpringSource Milestones Proxy</name>
<url>https://oss.sonatype.org/content/repositories/springsource-milestones</url>
</repository>
</repositories>
<build>
<finalName>springInActionMVCTemplate</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
`
# 1 楼答案
正确的标记区分大小写。(c:forEach)
# 2 楼答案
我在eclipse中也收到了这个警告。我还收到了其他警告,如:
为了修复eclipse中的这些警告,我所做的只是在pom文件中包含以下依赖项。请注意,我使用的是Servlet2.5API
您似乎正在pom文件中使用
<provided>
作为此依赖项。也许这就是你的问题所在# 3 楼答案
在《月食》中,同样的事情也发生在我身上。在我删除代码中出现的
<%@
和taglib
之间的空白后,它消失了所以现在它看起来像这样,警告消失了:
# 4 楼答案
实际上,您需要在JSP文件的顶部添加以下行:
此外,还需要从here下载JSTL jar文件,并将其添加到
WEB_INF/lib
文件夹中我在这里找到了答案: https://stackoverflow.com/a/8400733/3758439