Question

we're using Spring 3.1 for our webapp.

We currently map static resources with

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

and inside our skeleton template we refer to stylesheets like this:

<link rel="stylesheet" href="static/css/main.css">

What happens now is that I have no issues on loading css and images inside the main pages of the webapp (so like http://www.mysite.com ) but I get 404s inside inner pages (so like http://www.mysite.com/section1/chapter1 )

How can I solve this?

EDIT:

We're not using JSP/JSTL. We're using Thymeleaf.

Was it helpful?

Solution

According to the Themeleaf documentation, it would be something like this :

<link rel="stylesheet" th:href="@{/static/css/main.css}">

Or you can also use the JSTL c:url tag if you are using JSP :

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<link rel="stylesheet" href="<c:url value="/static/css/main.css" />">

OTHER TIPS

You probably want to use the Spring URL JSTL tag:

<link rel="stylesheet" href="<spring:url value="/static/css/main.css" />">

This should resolve the absolute URL based on the current context, and will work on HTML nested within subdirectories.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top