【问题标题】:Cannot resolve taglib with uri in Intellij IDEA无法在 Intellij IDEA 中使用 uri 解析 taglib
【发布时间】:2017-10-17 19:01:48
【问题描述】:

通过查看Udemy 上由Chad Darby 完成的教程系列JSP, Servlets and JDBC for Beginners: Build a Database App 并在BalusC answer 的帮助下,我在Intellij IDEA 中编写了以下代码

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%--To use JSTL core tags we need to import the following URL with prefix--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>Title</title>
</head>

<%
    // need to define a sample array
    String cities[]={"City1","City2","City3","City4"};
    // to use JSTL tags they have a to be a part of an attribute, either in the scope of the pageContext, session or application
    pageContext.setAttribute("myCities",cities);

%>
<body>
<%-- for printing them in for each loop--%>
<c:forEach var="cityName" items="${myCities}" >
    <%-- here we are using JSP expression language as ${...}}--%>
    ${cityName} <br/>
</c:forEach>

</body>
</html>

并按照教程作者(注意:教程在Eclipse IDE 上完成)和BalusC 答案的建议,在WEB-INF/lib 下添加JSTL 库。代码工作正常,但IDEA 编辑器给我

无法解析带有 uri http://java.sun.com/jsp/jstl/core 的 taglib

无法解析符号 'c:forEach'

并且这些线条是红色的,如图所示

为什么会这样?有没有其他地方可以在IDEA 中添加这些库?提前致谢

【问题讨论】:

  • stackoverflow.com/a/32444393/104891。依赖项中似乎缺少 JSTL 库。
  • @CrazyCoder 谢谢,它删除了红色线条。为了让JSTLIDEA 上工作,我们是否需要同时执行这两项操作?我的意思是向WEB-INF/lib 添加库并按照您的建议添加依赖项?
  • 您只需将库添加到依赖项中,然后如果您的 Web 容器尚未提供这些依赖项,则可以将这些依赖项包含到工件中,否则您将库的范围设置为已提供而不是将它们包含在工件中。

标签: java jsp intellij-idea jstl taglib


【解决方案1】:

我在处理基于 spring 的项目时收到了类似的消息。我通过在 pom.xml 中添加以下依赖项来解决它

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

接下来打开终端,然后执行 maven clean install

mvn -U clean install

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-18
    • 2021-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-21
    相关资源
    最近更新 更多