【问题标题】:Intellij IDEA jstl and taglibs not recognized even after adding dependency即使在添加依赖项后也无法识别 Intellij IDEA jstl 和 taglibs
【发布时间】:2016-10-23 08:28:28
【问题描述】:

我正在尝试将 jstltaglibs 依赖项合并到我的项目中。但是Intellij IDEA 无法识别<c:url value="" /> 标签。

这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.emusicstore</groupId>
    <artifactId>emusicstore</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>

        <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.3.3.RELEASE</version>
        </dependency>

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

        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>


    </dependencies>

</project>

这是我尝试在其中放置&lt;c:url..&gt; 标记的链接href 行

<title>Carousel Template for Bootstrap</title>

  <!-- Bootstrap core CSS -->
  <link href="<c:url value="/resources/css/bootstrap.min.css" />" rel="stylesheet">

这是屏幕截图。它似乎无法识别 &lt;c:url &gt; 标记和值(用引号括起来),就像将路径识别为纯文本一样。

这可能是什么原因造成的,我该如何解决?

谢谢。

【问题讨论】:

    标签: maven spring-mvc intellij-idea


    【解决方案1】:

    如果您想在您的 JSP 页面中使用 c:url 标记(或 core 组 JSTL 标记中的任何其他标记),则需要包含 JSTL Core 库:

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

    假设您有以下项目结构:

    您可以使用 bootstrap.min.css 文件的相对路径:

    <link href="<c:url value="../../resources/css/bootstrap.min.css" />" rel="stylesheet">
    

    或使用您的contextPath

    <link href="${pageContext.request.contextPath}/src/main/resources/css/bootstrap.min.css" rel="stylesheet"/>
    

    【讨论】:

    • 感谢您的回答。我不知道我必须添加 URL。我不得不在我的 dispatcher-servlet.xml 中添加 。我会注意你提供的信息。我很感激。
    猜你喜欢
    • 2021-12-26
    • 2023-01-18
    • 2022-11-10
    • 2013-02-09
    • 2021-04-16
    • 2019-07-03
    • 2013-07-10
    • 2016-09-25
    相关资源
    最近更新 更多