1

I have Java web app with following structure

WebContent->images->image.jpg
          ->js->test.js

I tried displaying an image in my jsp with the following code.

<img src="${pageContext.request.contextPath}/images/image.jpg" width="500" height="500" />

Firebug shows a GET request with the below URL

 http://localhost:8080/test/images/image.jpg

With a 200 ok response, but displays nothing.

I checked these questions:

Unable to load static contents (Images/JS) in web-application

Browser can't access/find relative resources like CSS, images and links when calling a Servlet which forwards to a JSP

But didn't help. Is there anything wrong with what I am doing?

My servlet mapping

<servlet>
<servlet-name>test</servlet-name>
<servlet-class>com.test.HomeServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Community
  • 1
  • 1
shazinltc
  • 3,616
  • 7
  • 34
  • 49

1 Answers1

4

The issue is that your servlet is catching all the request and passing it to the HelloServlet.

You need to avoid giving "<url-pattern>/</url-pattern>".

try changing the url-pattern to "<url-pattern>/test</url-pattern>"

bhatanant2
  • 596
  • 4
  • 9