Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPG Image not appearing in JSP of dynamic web project

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>
like image 336
somnathchakrabarti Avatar asked Apr 05 '12 02:04

somnathchakrabarti


People also ask

Where do I put images in Eclipse Dynamic Web Project?

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.


2 Answers

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.

like image 164
Steve H. Avatar answered Oct 19 '22 19:10

Steve H.


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.

like image 31
Carlos Gavidia-Calderon Avatar answered Oct 19 '22 18:10

Carlos Gavidia-Calderon