I am trying to use an image in the below index.jsp file in a dynamic web project that I created in Eclipse Indigo IDE. I have added the image under WEB-INF/images/pict1.jpg under WebContent of my project folder. But when I am running in browser, the image is not visible. The text and submit buttons are coming as expected. Am I missing anything? Any idea about how to make the image appear?
Any help will be appreciated. Below is the code.
Thanks,
Somnath
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<c:import url="/WEB-INF/javascript/index.js" />
<title>My Page</title>
</head>
<body>
<img alt="picture1" src="images/pict1.jpg">
<table border="0">
<tr><td valign="top">
<h1>Continue</h1></td><td><input type="submit"></td></tr>
<tr><td valign="top">
<h1>Continue</h1></td><td><input type="submit"></td></tr>
</table>
</body>
</html>
You have to add the image within the eclipse project structure for eclipse to package it and have it available on the webserver. Just having the image on your local file system doesn't work. To do this, drag and drop the file from your file system onto the eclipse project tree folder.
The image 'src' attribute is relative to the context root of your web application. Images don't go in WEB-INF. Move the 'images' folder to the "WebContent" folder of your project.
WEB-INF is usually reserved for metadata about your project that the container uses. Your application jsps and other resources are usually in folders relative to the WebContent folder.
According to this document from Oracle:
The WEB-INF directory is not part of the public document tree of the application. No file contained in the WEB-INF directory can be served directly to a client by the container.
Files contained in WEB-INF
folder are not accessible by URL. If you're using Eclipse, put pict1.jpg
image in WebContent/images
so your JSP point to a valid location.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With