I have a Java EE application that I create using Spring and Maven. It has the usual project structure. Here is a little hierarchy.
MyApplication src main webapp WEB-INF layout header.jsp styles main.css
I want to include this CSS file in my JSP. I have the following tag.
<c:url var="styleSheetUrl" value="/styles/main.css" /> <link rel="stylesheet" href="${styleSheetUrl}">
When deploying the application, the CSS page is not located. When I look at the source of the page, the href value is /MyApplication/styles/main.css . Inside WAR there is /styles/main.css . However, I get 404 when I try to access the CSS file directly in the browser.
I found that the dispatch of dispatch servlets was the cause of this problem. The display is as follows.
<servlet-mapping> <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
I believe the dispatch servlet does not know how to handle the CSS request. What is the best way to deal with this problem? I would prefer not to change all my query mappings.
source share