Struts html:img breaks URI

J

Joerg Gippert

Hello everyone!

I´m just trying to digest some webpages from our grafician using
Struts-tags and I´ve encountered a little problem, I´m a bit confused about.

Within a JSP I use the following tag to insert a picture: <html:img
src="images/navi/ball.gif" width="65" height="30" border="0"/> where the
directory structure is webapp/jsp/images. This works fine when I open
this page in my browser and it translates to
http://127.0.0.1:8080/MyWebapp/jsp/images/navi/ball.gif However, if the
JSP's include a form (html:form) and the Actionform class returns some
ActionErrors that need to be displayed on the JSP, the picture
disappears and the URI changed to
http://127.0.0.1:8080/MyWebApp/images/navi/ball.gif which is wrong since
the "jsp" directory is missing. Looks, like the tag looks after the
right path, when it is loaded and the JSP displays. But when the
ActionForm servlet modifies this page, it uses the path which is given
within the tag.

Does anyone know, how to avoid this problem?

Thanks for any hint!

Regards,
Joerg
 
W

Wendy S

Joerg Gippert said:
Hello everyone!
Within a JSP I use the following tag to insert a picture: <html:img
src="images/navi/ball.gif" width="65" height="30" border="0"/>
Does anyone know, how to avoid this problem?

If that's exactly what you have in your JSP, then just use a plain old HTML
<img> tag. If there's nothing dynamic about the output, there's no need to
get Struts involved in rendering the tag.

Alternately, I think you can specify the src as /jsp/images/navi/ball.gif
and it will be interpreted relative to the context. I'm not sure why
ActionErrors are causing this issue though. Might want to post it on
struts-user and report it as a bug if they don't have a good explanation.
 
J

Joerg Gippert

Hi Wendy,
If that's exactly what you have in your JSP, then just use a plain old HTML
<img> tag. If there's nothing dynamic about the output, there's no need to
get Struts involved in rendering the tag.

Yes, I checked back and I was assured there´s no dynamic content in it
so I wll use plain HTML now. That´s a workaround in this particular
case.
Alternately, I think you can specify the src as /jsp/images/navi/ball.gif
and it will be interpreted relative to the context. I'm not sure why
ActionErrors are causing this issue though. Might want to post it on
struts-user and report it as a bug if they don't have a good explanation.

I tried the path "/jsp/images/navi/ball.gif" as well, but it breaks up
again as soon as ActionForm returns with an ActionError. Happens also,
when using plain HTML <img> tag. I used the full path now
(MyWebApp/jps/images/ball.gif) and that works. I will post it on
struts-user. Maybe, it´s a configuration issue.

Thanks for your answer.

Regards,
Joerg
 
W

Wendy S

Joerg Gippert said:
I tried the path "/jsp/images/navi/ball.gif" as well, but it breaks up
again as soon as ActionForm returns with an ActionError. Happens also,
when using plain HTML <img> tag. I used the full path now
(MyWebApp/jps/images/ball.gif) and that works.

There's no way ActionErrors are affecting a plain old <img> tag.

If you use <img>, then don't use the leading slash (unless you put your
images under the ROOT webapp). There is no need to hard code the context
name, and every reason not to.
 
J

Joerg Gippert

Wendy said:
There's no way ActionErrors are affecting a plain old <img> tag.

If you use <img>, then don't use the leading slash (unless you put your
images under the ROOT webapp). There is no need to hard code the context
name, and every reason not to.

I´m not saying, it´s the ActionErrors, that modify somehow the URL
behind the tag (Struts or HTML). But if you open the page in a browser
and check the page source (by clicking on a "view page source" function
in your browser), the URL on the IMG tag really changed. It´s either a
bug or some configuration problem (tomcat/struts). It looks like, when
the jsp is shown the second time and the html:erros tag finds an error
and prints it, it takes the path, that´s inside the IMG-tag/html:img. If
you view the page source, when it´s loaded the first time, the
complete path has been added to whatever you state withing the
IMG/html:img tag.

I´m going to play with that some more. Maybe, I´ll found out what it is
or maybe I should take a nap ;)

Joerg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top