I am running a webapp in a Tomcat 7 container, and am recieving 404 errors when attempting to access static content (.css, etc.). Below is my directory structure:
- ROOT
- META-INF
- resources
- css
- WEB-INF
- classes
- lib
I have defined a default servlet in my deployment descriptor as follows:
<servlet>
<servlet-name>HomeController</servlet-name>
<servlet-class>controller.HomeController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HomeController</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
The HomeController servlet forwards the request to a .jsp, and the view is rendered properly.
request.getRequestDispatcher("view.jsp").forward(request,
response);
"view.jsp" has a link to a stylesheet (style.css) located in the css folder listed above. However, because the servlet is configured as a default servlet, I am now not able to access the static content in the css folder, and any request for this stylesheet returns a 404 error.
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/style.css" />
Is there any way around this? What is the best method for serving up static resources, but still being able to define a default servlet?