I'm having trouble with loading css and images when I have a servlet forward to a JSP. Specifically, when I set my welcome-file to index.jsp, the css is being loaded and my images are being displayed. However, if I set my welcome-file to HomeServlet and forward control to index.jsp, the css is not being applied and my images are not being displayed.
My css file is in web/styles/default.css. My images are in web/images/.
I'm linking to my CSS like so:
<link href="styles/default.css" rel="stylesheet" type="text/css" />
I'm displaying my images as follows:
<img src="images/image1.png" alt="Image1" />
Anyone know what is going on?
Thanks for any help.
UPDATE:
I've added the structure of the application, as well as some other information that might help.
The header.jsp file is the file that contains the link tag for the CSS:
<link href="${pageContext.request.contextPath}/styles/default.css" rel="stylesheet" type="text/css" />
The HomeServlet is set as my welcome-file (web.xml):
<welcome-file-list>
<welcome-file>HomeServlet</welcome-file>
</welcome-file-list>
The servlet is declared as followed in the web.xml:
<servlet>
<servlet-name>HomeServlet</servlet-name>
<servlet-class>com.brianblog.frontend.HomeServlet</servlet-class>
</servlet>
The servlet is mapped as follows (in web.xml):
<servlet-mapping>
<servlet-name>HomeServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Thanks again.
UPDATE #2:
I found the problem finally - my servlet was mapped incorrectly. Apparently when setting a Servlet as your welcome-file it can't have a URL pattern of "\". Which I find sort of weird, because wouldn't that stand for the root directory of the site?...
The new mapping is as follows:
<servlet-mapping>
<servlet-name>HomeServlet</servlet-name>
<url-pattern>/HomeServlet</url-pattern>
</servlet-mapping>