Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC CSS and JS not loading

Including floder structure

enter image description hereI am developing a web application in Spring MVC. I have issues loading CSS and JS files in JSP.

I googled for hours and tried all options, but not succeeded. Here is what i did

  1. tried to load as normal web app giving relative path
  2. tried including mvc:resources
  3. tried loading through Resource Servlet even then nothing worked.

All three were tried separately I am wondering what had i missed.

traditional link for #1

<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">

No changes done in mvc-config or web.xml

App Config for #2

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

Web XML for #3

<servlet>
    <servlet-name>Resource Servlet</servlet-name>
    <servlet-class>org.springframework.js.resource.ResouceServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Resource Servlet</servlet-name>
    <url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.js</url-pattern>
</servlet-mapping>

enter image description here

like image 797
ShasiSekar Avatar asked Dec 21 '25 17:12

ShasiSekar


1 Answers

this post helped me to resolve the issue.

How to handle static content in Spring MVC?

But still wondering why my actions were not helpful

like image 176
ShasiSekar Avatar answered Dec 23 '25 07:12

ShasiSekar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!