Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何正确引用CSS路径?_Java_Maven_Jsp_Intellij Idea_Classpath - Fatal编程技术网

Java 如何正确引用CSS路径?

Java 如何正确引用CSS路径?,java,maven,jsp,intellij-idea,classpath,Java,Maven,Jsp,Intellij Idea,Classpath,我使用Java/Spring项目,项目结构如下所示 我需要在index.jsp文件中引用app.css。目前,我在index.jsp中引用了以下方法,但应用程序没有获得CSS信息 <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Bitcoin Wallet</title> <link hre

我使用Java/Spring项目,项目结构如下所示

我需要在index.jsp文件中引用app.css。目前,我在index.jsp中引用了以下方法,但应用程序没有获得CSS信息

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Bitcoin Wallet</title>
    <link href="${pageContext.request.contextPath}/resources/css/app.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
</html>
在dispatcher-servlet.xml中,我提供了如下的资源路径:


我在localhost中得到的页面显然没有css。如何解决这个问题?

要在spring mvc项目中使用资源,您必须声明mvc:resources,将url映射到物理文件路径位置

<mvc:resources mapping="/resources/**" location="/resources/css/"
并将resources文件夹移动到webapp文件夹中,如下所示:

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