tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Micael Padraig Og mac Grene <caraun...@harbornet.com>
Subject Re: Images and STRUTS
Date Wed, 03 Apr 2002 18:36:44 GMT
THNX Craig

At 10:12 AM 4/3/02 -0800, you wrote:


>On Tue, 2 Apr 2002, Micael Padraig Og mac Grene wrote:
>
> > Date: Tue, 02 Apr 2002 22:29:28 -0800
> > From: Micael Padraig Og mac Grene <caraunltd@harbornet.com>
> > Reply-To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> > To: tomcat-user@jakarta.apache.org
> > Subject: Images and STRUTS
> >
> > I tried to do an ordinary image tag with the struts application, and could
> > not.  What is happening with that?  I could not get the index.jsp page to
> > reference an image in the same location.  I used the same page without
> > struts, and it worked.  I am just getting the clue on struts.  I am
> > familiar with the whole of Model 2 architectures, just not struts.  Is it
> > the forwarding mechanism that is calling the problem?
>
>You probably want to ask this sort of question on the STRUTS-USER list
>instead of here, but here's a common scenario that can cause Struts users
>(or anyone else using an architecture that uses RequestDispatcher.forward)
>grief:  if you are using relative path references for your images, those
>paths get resolved against the request URI that the browser submitted to
>-- not the URI of the page itself.  This is because the browser has no
>clue that a RequestDispatcher.forward() call was done on the server side.
>
>Example:
>
>- Your app is installed at "http://localhost:8080/myapp"
>
>- You have a main page "index.jsp", which therefore has the absolute URI
>   "http://localhost:8080/myapp/index.jsp".
>
>- You have an image in an "images" subdirectory, which therefore has the
>   absolute URI "http://localhost:8080/myapp/images/logo.gif".
>
>- You have Struts set up to use path based mapping to the controller
>   servlet, so you get URIs like "http://localhost:8080/myapp/do/getCustomer"
>   in it (to execute the "getCustomer" action).
>
>Now, consider what happens if you have the following tag in index.jsp:
>
>   <img src="images/logo.gif">
>
>and you execute "http://localhost:8080/myapp/do/mainMenu".  This fails to
>retrieve the image.  Why?  Because the *browser* is the one that resolves
>the absolute URI of the image -- and it resolves it against the URI that
>it submitted for this request:
>
>   http://localhost:8080/myapp/do/images/logo.gif
>
>which is obviously wrong.  Ways to get around this:
>
>- (Struts-specific) Use extension mapping instead of path mapping
>   for the controller.  Then, all requests and pages are in the same
>   "directory level" and relative references work as expected.
>
>- (Struts-specific) Use the <html:base/> tag in the <head> section
>   of your index.jsp page.  This creates an HTML <base> tag that tells
>   the browser to base relative references on *this* page, instead of
>   the request URI of the submit.
>
>- (Struts-specific) Use the Struts <html:img> tag instead, which knows
>   all about this problem and generates the correct URI automatically.
>
>- (General) Use a relative path like "../images/logo.gif" to convince
>   the browser to do the path correctly.
>
>- (General) Include your own <base> tag to tell the browser what the
>   absolute URL of this page is.
>
> >
> > Micael
> >
>
>Craig
>
>
>--
>To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
>For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
>Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>



--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message