Moupiya Ghosh
Moupiya Ghosh

Reputation: 15

CSS file not found in Spring application

I am trying to develop a Spring MVC application. The following is my file structure:

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

Here is my header.jsp where I want to include the 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>        

My dispatcher-servlet.xml has

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

I am using Spring-security for authentication. Hence in security-app-context.xml I have included

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

When I hit on the url, the css is not loading. I looked at the page-source and the link to the css is the following:

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

Please help.

Upvotes: 1

Views: 1199

Answers (1)

Master Slave
Master Slave

Reputation: 28569

resources folder should be moved under webapps folder.

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

         ....  

/src/main/resources is default maven location where you should place resources that you want to have available from the webapp's classpath

webapps on the other hand is the root of the webapp, under which all the static resources (js, css) should be placed

Upvotes: 1

Related Questions