ShasiSekar ShasiSekar - 1 month ago 5
CSS Question

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

Answer

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

Comments