Why Can't I Load Js And Css Files On My Pages?
I'm running a SpringMVC + Thymeleaf application and would like to load javascript and CSS on my HTML5 pages. My login.html is: <
Solution 1:
I have developed same application like you. Just developed it and working fine for me.
Here is config:
@EnableWebMvc
@Configuration
@ComponentScan(basePackages = { "org.tnt.base.api" })
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/css/**").addResourceLocations("/css/");
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
@Bean
public InternalResourceViewResolver jspViewResolver() {
InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setPrefix("/WEB-INF/views/");
bean.setSuffix(".html");
return bean;
}
....
}
Here's a screenshot of my structure that works:
Here's my login.html code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>TnT Quick Login</title>
<link href="../css/bootstrap.min.css" />
</head>
<body>
....
Solution 2:
I think problem is in this line.
registry.addResourceHandler("/WEB-INF/assets/**").addResourceLocations("/WEB-INF/assets/");
you can try this instead of:
registry.addResourceHandler("assets/**").addResourceLocations("/WEB-INF/assets/");
and then try to link your css or js, like this:
<script src="assets/js/jquery-2.0.3.min.js"></script>
or
<script src="/assets/js/jquery-2.0.3.min.js"></script>
Post a Comment for "Why Can't I Load Js And Css Files On My Pages?"