You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Micael Padraig Og mac Grene <ca...@harbornet.com> on 2002/04/23 17:32:43 UTC
Fwd: Re: Images and STRUTS: Craig
>Date: Tue, 23 Apr 2002 08:15:48 -0700
>To: struts@basebeans.com
>From: Micael Padraig Og mac Grene <ca...@harbornet.com>
>Subject: Fwd: Re: Images and STRUTS: Craig
>
>I have looked at this and have researched the area, Craig, and I have a
>simple question, I think. The suggested solution involving extension
>mapping is the default behavior of struts, is it not?
>
>At least the standard servlet mapping that came with structs in my case is:
>
>
> <!-- Standard Action Servlet Mapping -->
> <servlet-mapping>
> <servlet-name>action</servlet-name>
> <url-pattern>*.do</url-pattern>
> </servlet-mapping>
>
>
>Essentially what I want to do is the following: access html pages which
>reference .swf (Flash) files (templates) with relative references, e.g.,
>template1.swf, holding arrays of other .swf files (photos) which all have
>relative references to the same directory by default, e.g. photo1.swf,
>photo2.swf, photo3.swf, etc. I want to forward to the html pages through
>the controller and the ActionForward functionality in order to preserve
>security and other matters. But, my html pages are not seeing the
>template pages. I can solve that by using relative references in the html
>pages, but not in the Flash template.swf pages. So, what to do?
>
>Why won't the relative references work when the default mapping is to the
>extension *.do?
>
>Micael
>
>
>>Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm
>>List-Unsubscribe: <ma...@jakarta.apache.org>
>>List-Subscribe: <ma...@jakarta.apache.org>
>>List-Help: <ma...@jakarta.apache.org>
>>List-Post: <ma...@jakarta.apache.org>
>>List-Id: "Tomcat Users List" <tomcat-user.jakarta.apache.org>
>>Reply-To: "Tomcat Users List" <to...@jakarta.apache.org>
>>Delivered-To: mailing list tomcat-user@jakarta.apache.org
>>Date: Wed, 3 Apr 2002 10:12:36 -0800 (PST)
>>From: "Craig R. McClanahan" <cr...@apache.org>
>>To: Tomcat Users List <to...@jakarta.apache.org>
>>Subject: Re: Images and STRUTS
>>X-Spam-Rating: localhost 1.6.2 0/1000/N
>>X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N
>>
>>
>>
>>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 <ca...@harbornet.com>
>> > Reply-To: Tomcat Users List <to...@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: <ma...@jakarta.apache.org>
>>For additional commands: <ma...@jakarta.apache.org>
>>Troubles with the list: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>