2017-06-20 47 views
0

我有一個Java/Spring項目工作,下面提供的項目結構,如何正確引用CSS路徑?

enter image description here

我需要引用app.cssindex.jsp文件。目前,我在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,我提供如下的資源路徑,

enter image description here

頁我在本地主機獲得顯然不具備的CSS。如何解決這個問題?

回答

1

要在spring mvc項目中使用資源,您必須聲明mvc:resources,將url映射到物理文件路徑位置。

<mvc:resources mapping="/resources/**" location="/resources/css/" 

當您使用/resources/在JSP文件春天將這個URL映射到/resources/css/

接下來,您可以在JSP文件中引用CSS文件:

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

並移動resources文件夾放到webapp文件夾