Java 未知标签 (c:foreach)。在日食
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22708241/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unknown tag (c:foreach). in eclipse
提问by Capril Aprilovich
I have jstl code and it builds by maven well... But Eclipse had compilation error "Unknown tag (c:foreach)."
我有 jstl 代码,它由 Maven 构建得很好......但是 Eclipse 有编译错误“未知标签(c:foreach)”。
code are here:
代码在这里:
<%@ 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>
could someone help me to avoid this promlem?
有人可以帮我避免这个问题吗?
There are full pom: ` http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
有完整的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>
`
`
回答by Alan C. S.
I was also getting this warning in eclipse. I was also getting other warnings such as:
我在 eclipse 中也收到了这个警告。我还收到其他警告,例如:
Unknown tag
(c:if)
or Unknown tag(c:set)
etc.
未知标签
(c:if)
或未知标签(c:set)
等。
To fix these warning in eclipse, all i did was to include the following dependency in my pom file. Please note that I am using the servlet 2.5 api.
为了在 Eclipse 中修复这些警告,我所做的只是在我的 pom 文件中包含以下依赖项。请注意,我使用的是 servlet 2.5 api。
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
You seem to be using <provided>
for this dependency in your pom file. Maybe that's causing your problem ?
您似乎<provided>
在 pom 文件中使用了此依赖项。也许这导致了你的问题?
回答by Niharika
the correct tag is case sensitive. (c:forEach)
正确的标签区分大小写。(c:forEach)
回答by Osmar
Same thing was happening to me in Eclipse. It dissapeared after I deleted the white space between <%@ and taglib that appears in your code.
我在 Eclipse 中也发生了同样的事情。我删除了代码中出现的 <%@ 和 taglib 之间的空白后,它就消失了。
So now it appears like this and the warning is gone:
所以现在它看起来像这样并且警告消失了:
回答by George
What you actually need is to add the following line on top of your JSP files:
您实际需要的是在 JSP 文件的顶部添加以下行:
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
Also, you need to download the JSTL jar files from hereand add them to WEB_INF/lib
folder.
此外,您需要从这里下载 JSTL jar 文件并将它们添加到WEB_INF/lib
文件夹中。
Found my answer here: https://stackoverflow.com/a/8400733/3758439
在这里找到我的答案:https: //stackoverflow.com/a/8400733/3758439