I have a Java EE application that I am building with Spring and Maven. It has the usual project structure. Here is a bit of the hierarchy.
MyApplication
Add the following in web.xml
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
and use the following to include your css
<link rel="stylesheet" href="styles/main.css">
You need to configure Spring to handle the static resources (CSS, JS, images) separately from servlet requests to your app. To do this, configure your Spring config to map requests to static files via a separate top level directory (e.g. "static"):
<!-- Where to load static resources (css, js, images) -->
<mvc:resources mapping="/static/**" location="/" />
Then change your JSP to use the path /static/styles/main.css
.
Note, convention dictates you name your "styles" directory to "css".