Michal Sipek
Michal Sipek

Reputation: 494

Unable to load CSS in Spring Mavenized project

I have a problem with CSS path in my project. This is the file structure of a Spring Maven project.

https://i.sstatic.net/kbzpf.jpg

In jsp page I wrote:

<link rel="stylesheet" href="/Treninky/css/bootstrap.css" />

But it still does not work. I can't find a solution. Could anyone help me?

Upvotes: 0

Views: 696

Answers (4)

Jubin Patel
Jubin Patel

Reputation: 2052

Flelix good advice
Best practice to get path of any folder from the project is: (as per flelix advice structure),

<LINK REL="SHORTCUT ICON" HREF="<%=request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath()%>/src/css/bootstrap.css">

Upvotes: 0

Vahid Forghani
Vahid Forghani

Reputation: 343

add this to your web.xml

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.css</url-pattern>
</servlet-mapping>

and it's better to move your css to another directory like src/main/resources or somewhere that not in WEB-INF

Upvotes: 2

Felix
Felix

Reputation: 38112

I'd suggest you to put your css file under css folder inside src folder:

Treninky >
         src >
              css/bootstrap.css   

Then you can use:

<link rel="stylesheet" href="/Treninky/src/css/bootstrap.css" />

Upvotes: 0

Jorge_B
Jorge_B

Reputation: 9872

Resources under WEB-INF directory are not visible outside the application. You should have your /css directory straight under your webapp directory in order for it to be visible.

Something like

src/
   /main
        /webapp
               /Treninky
                        /css/*.css

And then your /css directory would be reachable

Upvotes: 2

Related Questions