2014-11-16 36 views
1

我正在嘗試開發Spring MVC應用程序。以下是我的文件結構:在Spring應用程序中找不到CSS文件

-/src 
    /main 
     /resources 
      /css 
      main.css 
     /webapps 
      /screens 
      header.jsp 
      .... 
      /WEB-INF 
      web.xml 
      .... 

這是我header.jsp,我想包括main.css

<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<link rel="stylesheet" type="text/css" href="<c:url value="/resources/css/main.css"/>">  

<title>Insert title here</title></head>   

dispatcher-servlet.xml

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

我使用Spring的安全性進行驗證。因此,在security-app-context.xml我已經包括

<intercept-url pattern="/resources/css/main.css" access="permitAll" />  

當我打的網址,該CSS沒有加載。我看了頁面源和鏈接到CSS爲以下內容:

http://localhost:8080/BlogWar-1.0-SNAPSHOT/resources/css/main.css  

請幫忙。

回答

1

資源文件夾應該移到webapps文件夾下。

-/src 
    /main 
     /resources 
     /webapps 
      /resources 
      /css 
       main.css 
      /screens 
      header.jsp 
      .... 
      /WEB-INF 
      web.xml 

     .... 

/src/main/resources是默認的Maven的位置,你應該把你想擁有可從Web應用程序的,另一方面classpath中

webapps是Web應用程序的根目錄資源,所有的靜態資源在其下( js,css)應該放置

相關問題