CSS file in a Spring WAR returns a 404
Posted
by
Rachel G.
on Stack Overflow
See other posts from Stack Overflow
or by Rachel G.
Published on 2012-09-10T03:02:07Z
Indexed on
2012/09/10
3:38 UTC
Read the original article
Hit count: 180
I have a J2EE application that I am building with Spring and Maven. It has the usual project structure. Here is a bit of the hierarchy.
MyApplication
src
main
webapp
WEB-INF
layout
header.jsp
styles
main.css
I want to include that CSS file in my JSP. I have the following tag in place.
<c:url var="styleSheetUrl" value="/styles/main.css" />
<link rel="stylesheet" href="${styleSheetUrl}">
When I deploy the application, the CSS page isn't being located. When I view the page source, the href is /MyApplication/styles/main.css
. Looking inside the WAR, there is a /styles/main.css
. However, I get a 404 when I try to access the CSS file directly in the browser.
I discovered that the reason for the issue was the Dispatcher Servlet mapping. The mapping looks as follows.
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I imagine the Dispatcher Servlet doesn't know how to handle the CSS request. What is the best way to handle this issue? I would rather not have to change all of my request mappings.
© Stack Overflow or respective owner