Search code examples
javajspjakarta-eejsp-tags

Image cannot be displayed by a simple JSP


I have a JSP which simply shows and image as header. I will change this into a .tag file for custom tag development. I am doing this in eclipse and my project structure is -

enter image description here

The jsp i am trying to run on the server is Header.jsp under jsp folder. The problem is that the image is not displayed, even when I use the fully qualified path of the image. Insted, i see a red cross. How do I fix this ?

When I use this file as a .tag file referenced by another jsp, the contents of tag do not appear in that jsp.

JSP code -

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib prefix="myTags" tagdir="/WEB-INF/tags"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<img src="/images/java_logo.gif"><br>

</body>
</html>

Solution

  • The URL you specify here is absolute for your site, not the web app.

    <img src="/images/java_logo.gif">
    

    So try to use (with WEBAPPROOT replaced by the correct name)

    <img src="/WEBAPPROOT/images/java_logo.gif">
    

    or make it relative:

    <img src="../images/java_logo.gif">