0

I am trying to display a png image on my jsp page. However, it just displays a small icon with the alt text. I am pretty sure it has something to do with the image path because it is giving a 404 error saying the resource is not found. I have tried looking for a solution on StackOverflow, however, all the solutions have not worked for me. If anyone could help or direct me to why the image will not display that would be great. Thank you!

Maybe my servlet configuration is also relevant: todo-servlet.xml

*If it is relevant I am using maven and spring MVC.

JSP PAGE

What gets displayed

Kalaiselvan
  • 2,095
  • 1
  • 18
  • 31
  • Is the images folder web accessible? Where are you serving css and js from? – Raul Sauco Jan 09 '18 at 02:25
  • Hello, I am not sure what you mean by web accessible, I wrote all the html and css in the jsp page. Also I am using Java not Javascript. – Thomas Ding Jan 09 '18 at 02:27
  • https://stackoverflow.com/questions/37071743/cant-display-image-on-jsp-page?rq=1 – rickz Jan 09 '18 at 02:32
  • Static content, images, css, Javascrip files, if you are using any, are fetched in a different request than the main page. The server has to be able to access the folder where those files are but it looks like the image file that you are trying to serve is in a subfolder of the src directory which, usually, the web server cannot access directly. – Raul Sauco Jan 09 '18 at 02:33
  • 4
    Possible duplicate of [Can't display image on jsp page](https://stackoverflow.com/questions/37071743/cant-display-image-on-jsp-page) – rickz Jan 09 '18 at 02:39
  • I have tried that solution before did not work – Thomas Ding Jan 09 '18 at 02:42
  • They had the same file structure as you are using here. It shoud work. – rickz Jan 09 '18 at 02:44
  • You can see the url that your browser is trying in your console. All that is missing is the context path. – rickz Jan 09 '18 at 02:46
  • @rickz I am a beginner at this so I am not 100% clear on what you mean by missing the context path? – Thomas Ding Jan 09 '18 at 02:48
  • Context is the name of your web app. You were using a page relative path. You should use a server relative path. Start your img src with "/yourContextName/images/..... See the answer at the link I posted. – rickz Jan 09 '18 at 03:07
  • Your image file should be outside of WEB-INF folder – Mizuki Jan 09 '18 at 03:10
  • @Alice it is outside of the WEB_INF folder – Thomas Ding Jan 09 '18 at 03:13

0 Answers0