samedi 11 avril 2015

How to load CSS for different URL in spring MVC app

I have a problem loading css for different URL.


This is my current structure:



-webapp
|--resource
|---css
|---generalize.css
|---js
|---images
|--WEB-INF
|---views
|---login
|---dashboard


This is my spring configuration to look for the resources:



<mvc:resources mapping="/resources/**" location="/resources/" />


And in the jsp page, I try to load it as:



<link href="<c:url value="resources/css/generalize.css" />" rel="stylesheet" type="text/css" />


If I have an url like localhost:8888/myapp/login or localhost:8888/myapp/dashboard, the css will apply fine. But when I try to map the dashboard page with the url localhost:8888/myapp/user/dashboard, the page loses its css style. Would anyone help to explain how would be the correct way to load the css (or using the resources)?


I have tried to prepend the contextPath as below but it does not work as well.



<link href="<c:url value="${pageContext.request.contextPath}/resources/css/generalize.css" />" rel="stylesheet" type="text/css" />

Aucun commentaire:

Enregistrer un commentaire