You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tom Miller <tm...@kdsi.net> on 2001/03/19 21:53:16 UTC

html:img tag cannot find image

Hello all,

It seems that the html:img tag is able to find images in the context
root, but not in subdirectories.
When I specify an image with the html:img tag like this:
<html:img src="green-ball.gif"/>
the images appear.

But when I specify a subdirectory like this:
<html:img src="WEB-INF/images/orange-ball.gif"/>
the images are missing when the page renders, i.e. little red X symbol
in the browser.

Here is a pared down JSP that illustrates the problem. It gives the same
results whether I include the <html:base/> tag or not.

I'm using Struts 1.0b1 and Tomcat 3.2.1.

TIA for any help.

Tom
--------------------------------------------------------------------------

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<html:html>
   <html:base/>
<head>
</head>

<body>
   Dot One<html:img src="green-ball.gif"/>   <% /* image shows in
browser */ %>
   <p>
   Dot Two<html:img src="WEB-INF/images/orange-ball.gif"/> <% /* image
missing in browser */ %>

</body>
</html:html>
--------------------------------------------------------------------------

Tom Miller
Miller Associates, Inc.
tmiller@kdsi.net
641.469.3535 Phone
413.581.6326 FAX



Re: html:img tag cannot find image

Posted by Maya Muchnik <mm...@pumatech.com>.
Can you try <html:img src="/WEB-INF/images/orange-ball.gif"/>
Maya

Tom Miller wrote:

> Hello all,
>
> It seems that the html:img tag is able to find images in the context
> root, but not in subdirectories.
> When I specify an image with the html:img tag like this:
> <html:img src="green-ball.gif"/>
> the images appear.
>
> But when I specify a subdirectory like this:
> <html:img src="WEB-INF/images/orange-ball.gif"/>
> the images are missing when the page renders, i.e. little red X symbol
> in the browser.
>
> Here is a pared down JSP that illustrates the problem. It gives the same
> results whether I include the <html:base/> tag or not.
>
> I'm using Struts 1.0b1 and Tomcat 3.2.1.
>
> TIA for any help.
>
> Tom
> --------------------------------------------------------------------------
>
> <%@ page language="java" %>
> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
>
> <html:html>
>    <html:base/>
> <head>
> </head>
>
> <body>
>    Dot One<html:img src="green-ball.gif"/>   <% /* image shows in
> browser */ %>
>    <p>
>    Dot Two<html:img src="WEB-INF/images/orange-ball.gif"/> <% /* image
> missing in browser */ %>
>
> </body>
> </html:html>
> --------------------------------------------------------------------------
>
> Tom Miller
> Miller Associates, Inc.
> tmiller@kdsi.net
> 641.469.3535 Phone
> 413.581.6326 FAX


Re: html:img tag cannot find image

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Mon, 19 Mar 2001, Tom Miller wrote:

> Hello all,
> 
> It seems that the html:img tag is able to find images in the context
> root, but not in subdirectories.
> When I specify an image with the html:img tag like this:
> <html:img src="green-ball.gif"/>
> the images appear.
> 
> But when I specify a subdirectory like this:
> <html:img src="WEB-INF/images/orange-ball.gif"/>
> the images are missing when the page renders, i.e. little red X symbol
> in the browser.
> 
> Here is a pared down JSP that illustrates the problem. It gives the same
> results whether I include the <html:base/> tag or not.
> 
> I'm using Struts 1.0b1 and Tomcat 3.2.1.
> 
> TIA for any help.
> 

The issue is that a servlet container is prohibited (in the spec) from
serving any file from the WEB-INF directory directly to a client.  This is
to prevent people from snooping sensitive information from your web.xml
file, or other config files you might have stored here.

If you want your image to be displayed, move it to some directory other
than WEB-INF.  Then, the URLs you use with the <html:img> tag will
correspond to what you would use with a regular HTML <img> tag.


> Tom

Craig McClanahan