2

Possible Duplicate:
Browser can't access CSS and images when calling a Servlet which forwards to a JSP

I know this question is asked again and again, but I just couldn't get this to work.

folder structure http://kauko.pingtimeout.net/venttiCap.JPG

I have my images in the WebContent/kuvat/ folder. I also put one of the images directly into the WebContent folder (hertta1.gif). But when I try to use the images like this

<img src="kuvat/hertta1.gif" /> or <img src="hertta1.gif" />

nothing happens. The kuvat/*gif request results in a 404, while the other one is apparently an empty response.

GameServlet is the only Servlet, and it's mapped to '/'. So when using the application I use the address "http://localhost:8080/VenttiWeb/"

I'm using Tomcat7

Community
  • 1
  • 1
T.Kaukoranta
  • 415
  • 10
  • 25

1 Answers1

1

Have you tried something like this?

<img src="/kuvat/hertta1.gif" /> or <img src="/hertta1.gif" />

Also, it may not be a good idea to hardcode the context path. In a JSP you might try something like:

<img src="${pageContext.request.contextPath}/kuvat/hertta1.gif"/>

And something similar can be done from a servlet using ServletContext instead of a PageContext.

Reference: http://www.coderanch.com/how-to/java/ResourceUrlProblems

user506069
  • 771
  • 1
  • 6
  • 14
  • This wasn't exactly the right answer, but I marked it anyway since it helped me find my problem. I only had one servlet, which was mapped to '/'. When I changed it to '/Game', everything started working. Could anyone explain why it works like that? – T.Kaukoranta Apr 05 '12 at 05:34
  • 1
    When you map your servlet to '/' it takes the place of the default servlet, which is responsible for sending static content. Since I assume your servlet didn't extend or otherwise implement the functionality of the default servlet, Tomcat couldn't serve the static content correctly. Default servlet doc: http://tomcat.apache.org/tomcat-7.0-doc/default-servlet.html – user506069 Apr 05 '12 at 13:57