0

Hi I am trying to add css and js to my project. I have created Spring starter project and have placed css and js files in webapp/resources/ but it's not working.

enter image description here

How should I include them in my .html file? What is the path?

I have also added

public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
          .addResourceHandler("/resources/**")
          .addResourceLocations("/resources/"); 
    }

to my springConfig class.

  • Possible duplicate of [Spring MVC - Project structure - best practices](https://stackoverflow.com/questions/23550273/spring-mvc-project-structure-best-practices) – Patrick Barr Jul 12 '17 at 22:05
  • @PatrickBarr sorry but I haven't found my answer there –  Jul 12 '17 at 22:38

1 Answers1

0

1.Try to point your path to static folder

registry
.addResourceHandler("/static/**")
.addResourceLocations("/static/")
.setCachePeriod(604800); // <- this catches your resource so you dont need to download everytime

2. How should I include them in my .html file? What is the path? If you are using JSTL tags on your views, use c taglib

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<link href="<c:url value="/static/img/favicon.ico" />" rel="shortcut icon" />
Boldbayar
  • 862
  • 1
  • 9
  • 22