This is a spring boot app using jsp I've tried many solutions, but I can't seem to get CSS integrated with my JSP files. My JSP files are under /WEB-INF/jsp and my css files are in /resources/static/css.
^ The first one doesn't work, but the second one with the link works.
Application.properties file:
#
# MVC Properties
#
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
server.servlet.context-path=/tfhk
spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**
Project structure: link to project structure
Try this in your view:
<link href="/css/main.css" rel="stylesheet">
Also somewhere in your config do this (in spring security context if using it):
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/public/"
};
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.