Spring cannot load css files

Spring cannot load my css files, and this is my architecture:

  • Project
    • Webcontent
    • WEB-INF
      • pages
        • index.jsp
      • CSS
        • Jquery-ui.css
+2
source share
2 answers

You can put the css file and other files, such as javascript, images in the resources of the
Project folder

Webcontent
resources  
     css
         jquery-ui.css
WEB-INF
   pages
     index.jsp

And put the following line in spring configuration

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

And give the link in jsp pages like

<link href="${pageContext.request.contextPath}/resources/css/jquery-ui.css"
    rel="stylesheet">
+4
source

As fvu explained, the contents inside are WEB-INFnot accessible via HTTP. The directory Webcontentin your directory structure looks like it was created for this specific purpose: storing CSS files, images, and JavaScript files.

CSS HTTP , Spring MVC HTTP-. <mvc:resources> bean:

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

CSS URL-:

http://localhost:8080/you-app-name/webcontent/...

<mvc:resources> Stackoverflow.

+2

All Articles