2

I'm working in a Spring MVC project and I have the following problem:

This is my folders hierarchy

--src
   --main
      --webapp
         --WEB-INF
            --views
                --css
                   --mystyle.css
                ---myview.html

and this is how I call mystyle.css in myview.html

href="css/mystyle.css"

but my CSS doesn't show up.

But if I put my views folder outside of WEB_INF, my CSS does show up and it works like this:

--src
   --main
      --webapp
          --views
              --css
                 --mystyle.css
              --myview.html
         --WEB-INF

And I call my CSS the same way like before href="css/mystyle.css"

Is there something different that I didn't notice? Why doesn't my CSS works outside of the WEB-INF folder and it does not work inside?

stackUser2000
  • 1,615
  • 11
  • 32
  • 55
  • 1
    possible duplicate of [Cannot access CSS files defined under WEB-INF from JSP](http://stackoverflow.com/questions/26463168/cannot-access-css-files-defined-under-web-inf-from-jsp) – William Price Dec 22 '14 at 20:42

2 Answers2

1

Right, CSS files need to be in a path that is directly visible to the browser. WEB-INF is hidden.

GriffeyDog
  • 8,186
  • 3
  • 22
  • 34
1

While it is true that you cannot access resources under WEB-INF folder directly, you can still keep your location and add a configuration like

 <resources mapping="/css/**" location="/WEB-INF/views/css/" />

in your spring mvc configuration, or a java config equivalent if you're using java config. Note that you should be accessing css with an absolute URL, so if you're serving from root

href="/css/mystyle.css"

or prepand a context if you're using one

Master Slave
  • 27,771
  • 4
  • 57
  • 55