JPG Image not appearing in JSP of dynamic web project

Go To StackoverFlow.com

5

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>
2012-04-05 02:41
by somnathchakrabarti


12

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.

2012-04-05 02:48
by Steve H.
Thanks Steve. It works - somnathchakrabarti 2012-04-05 12:55
i have images folder in webContent. i wrote src="images/x.png" . But images is not show - partho 2016-09-11 06:24
i have images folder in webContent. i wrote src="images/x.png" . But images is not show - partho 2016-09-11 06:24


2

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.

2012-04-05 02:49
by Carlos Gavidia
Thanks Carlos. Yes, I did exactly that and it worked - somnathchakrabarti 2012-04-05 12:56
Ads