【问题标题】:Unknown tag (c:foreach). in eclipse未知标签 (c:foreach)。在日食
【发布时间】:2014-05-07 15:27:17
【问题描述】:

我有 jstl 代码,它由 maven 构建得很好……但是 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>

`

【问题讨论】:

  • 你添加了这个依赖吗? javax.servletjstl1.2提供
  • 是但没有范围...现在添加但没有更改...
  • JSTL 1.2 要求 web.xml 中至少有 Servlet 2.4 声明。因此,请确保您的 web.xml 具有正确的根声明,最好是您的 servlet 容器支持的最高支持版本(Tomcat 7 是 Servlet 3.0,Tomcat 6 是 Servlet 2.5,Tomcat 5.5 是 Servlet 2.4)。
  • 查看我在 tomcat 6 和 Servlet 2.5 上运行的附加内容...这可能是唯一的 eclipse 问题吗?因为应用程序编译和运行良好,但是 eclipse 显示编译警告...
  • @BalusC 为什么这是重复的? @Capril 有问题提到,jstl 库已添加,但警告仍然存在。我看到@Osmar 的回答,它解决了我同样的问题,因为愚蠢的空间。

标签: java eclipse maven jstl


【解决方案1】:

Eclipse 中也发生了同样的事情。在我删除代码中出现的&lt;%@taglib 之间的空格后,它就消失了。

所以现在它看起来像这样,警告消失了:

<%@taglib  uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

【讨论】:

    【解决方案2】:

    您真正需要的是在您的 JSP 文件顶部添加以下行:

    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    

    另外,您需要从here 下载JSTL jar 文件并将它们添加到WEB_INF/lib 文件夹中。

    在这里找到我的答案: https://stackoverflow.com/a/8400733/3758439

    【讨论】:

      【解决方案3】:

      我在 Eclipse 中也收到了这个警告。我还收到了其他警告,例如:

      未知标签(c:if)或未知标签(c:set)

      为了在 Eclipse 中修复这些警告,我所做的只是在我的 pom 文件中包含以下依赖项。请注意,我使用的是 servlet 2.5 api。

              <dependency>
                  <groupId>javax.servlet</groupId>
                  <artifactId>jstl</artifactId>
                  <version>1.2</version>
              </dependency>
      

      您似乎在您的 pom 文件中使用 &lt;provided&gt; 作为此依赖项。也许这就是你的问题?

      【讨论】:

        【解决方案4】:

        正确的标签区分大小写。 (c:forEach)

        【讨论】:

        • 原始帖子的格式已经正确。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-09
        • 2018-03-16
        • 2012-01-14
        • 2018-05-12
        • 1970-01-01
        相关资源
        最近更新 更多