Instead of using the ${contextPath}
, the best way to do with Spring is to use a framework resource to map the resources of the application.
If you are using configuration via XML, it would be like this:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
...
<!-- Mapeia os recursos abaixo da pasta resources para estarem disponíveis no path /resources/ -->
<mvc:resources mapping="/resources/**" location="/resources/" />
...
</beans>
Or using WebMvcConfigurer
:
@EnableWebMvc
@Configuration
public class WebConfig implements WebMvcConfigurer {
...
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/WEB-INF/resources/");
}
...
}
And on your page you would use only:
<link href="/resources/css/reset.css" rel="stylesheet" type="text/css" media="all"/>