Insert image into jsp page

Viewed 31076

I am sorry that I need to ask this but I already spent three days trying to do this. I am buidling Java Web application and I want to include image to JSP page. Project name is realestates and I have Files folder inside realestates folder.

My code is like this:

<img alt="govno" src="<%=request.getContextPath() + "/Files/kurac.jpg"%>" style="width: 400px; height: 300px;">

This is what gets generated on page after I open it in browser:

<img alt="govno" src="/realestates/Files/kurac.jpg" style="width: 400px; height: 300px;">

BUT, image is not dispayed, only alt "govno" is written. I have tried many many paths (relative, absolute, changed folder structure million times and whatever I could think of and find on internet but nothing helped). Who would say that such a thing will be so hard to do???

Folder structure on Tomcat server after deployment is:

webapps
 - realestates
   |- WEB-INF
   |- Files
     |- kurac.jpg
5 Answers

Webpage never allows accessing any local files.
This means that if you write img src="c:\imagesfolder\abc.jpg" in the jsp file it will not work (it can work only in some editor but it will not work using a browser).

img src="http://localhost.8080/imageshow/sendimage/12/abc.jpg" width="100" height="100"
Related