I am trying to include an image (my company logo) in an HTML page. When my HTML is not hosted on tomcat and I give absolute file path in HTML, everything works fine and I am able to see the image
The following works perfectly fine outside tomcat:
<footer>
<br/><br/><br/><br/><br/><br/><br/>
<center><p>Powered by: </p>
<img src="D:\MyImagesFolder\logo.png" /></center>
</footer>
BUT. When I access the same HTML from localhost:8080/myform, the image does not load
I have tried the following
- Added context.xml in my web project's META-INF and added the following to it
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/MyContext/images" docBase="D:\MyImagesFolder" crossContext="true"/>
AND in the HTML
<img src="MyContext/images/logo.png" />
then added a leading slash to make it
<img src="/MyContext/images/logo.png" />
No LUCK
Then I tried the following
- Under apache-tomcat-9.0.0.M21\conf I created a folder Catalina and a folder localhost inside Catalina
Created an XML file named MyContext#images.xml in localhost which was having the following
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/MyContext/images" docBase="D:\MyImagesFolder" crossContext="true" />
and in the HTML I tried
<img src="MyContext/images/logo.png" />
and
<img src="/MyContext/images/logo.png" />
NO LUCK
I put my image inside \apache-tomcat-9.0.0.M21\webapps\ROOT and in the html
NO LUCK
- As I am running tomcat inside eclipse, I tried putting MyContext#images.xml in "Tomcat v9.0 Server at localhost-config" in eclipse and
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/MyContext/images" docBase="D:\MyImagesFolder" crossContext="true"/>
in the XML
and in the HTML I tried
<img src="MyContext/images/logo.png" />
and
<img src="/MyContext/images/logo.png" />
NO LUCK
What is missing and where?