Struts has a tag that will put the context path on the front of the src URL
for you. Here's an example:

<html:img page="/images/leiste_oben.jpg" width="430" height="80" border="0"
alt=""/>

If you want to reserve the option to internationalize what image gets
displayed, Struts has good support for that, too. For instance, if you have
a button image with some text on it, and you want to be able to show
different images for different languages, you can put the image path in the
ApplicationResources.properties file and use something like this:

<html:img pageKey="button.clickMe.src"/>

You can also use the altKey attribute of the <html:img> tag to
internationalize the ALT, um, thingy.

<html:img pageKey="button.clickMe.src" altKey="button.clickMe.alt"/>

In your base ApplicationResources.properties file, you might have something
like this:

button.clickMe.src=/images/button_clickMe.jpg
button.clickMe.alt=Click Me

You can override these values for other languages in locale-specific
versions of the ApplicationResources.properties file.

One thing to be careful of with specifying images this way is that if you
set the size in the <html:img> tag (which is a good idea to speed rendering
performance in the browser), make sure that all the images for a given
button match the size that is specified.

They don't exist now, but it might be useful if heightKey and widthKey
attributes were added to the <html:img> tag to allow those to be looked up
in the properties file as well. That way you could specify different sizes
for the images if they happen to be different for different locales.

For complete documentation, see the online docs for <html:img>, here:
http://jakarta.apache.org/struts/userGuide/struts-html.html#img

-Max

----- Original Message ----- 
From: "Rajesh M Vasudevan" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Friday, September 26, 2003 11:32 PM
Subject: Re: [Question] Image path - Best way?


> Hi guys,
>
> I tried the following, and it seems to work good:
> <img src="<%=request.getContextPath()%>/images/leiste_oben.jpg"
width="430"
> height="80" border="0" alt="">
>
> Is this the right way?  Is there a way to specify it as a Resource? Can
you
> give me a tutorial link of how to do that..
>
> Thanks
> Rajesh
>
> > Hi
> >
> > What is the best way to give image paths in JSP pages?  I see that an
> image
> > path given in a certain way works for .jsp files, but the same path
fails
> > for pages loaded through a .do and vice versa.
> >
> > Is there a standard way that struts instructs by which images can be
> defined
> > in a resource configuration file and refer to them in the jsp pages as
> > resource strings, just like application resources?  OR Is there a way to
> > refer to an image which works well for both .do or .jsp.
> >
> > Please advise..
> >
> > Regards,
> > Rajesh
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to