You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Xiao Xiao <xi...@gmail.com> on 2006/09/27 05:49:33 UTC

Diff behaviors for relative-path resource mapping in TC4 and TC5

Hi,
   Saying i have the following web-app structure:
      WEB-INF/web.xml
      html/logo.gif
      html/welcome.html
      logo.gif
   in the web.xml, html/welcome.html is defined as one of the welcome-file,
which includes an image defined as src="./logo.gif". My question is which
logo will be shown when i try to access web-app? Seems TC4  (4.1.31) and
TC5 (5.1.12) handle this differently.
   In TC5, the request is mapped to html/welcome.html, but the context is
still at the root-level, so the logo.gif at root level is returned; while in
TC4, it will redirect to html/welcome.html, with the context changes to html
as well -- so html/logo.gif is returned. For me, it seems TC5 makes more
senses, but anyone can help me confirm this? (as is it a TC4 bug? a change
in the spec? etc?)
   Thanks.
xiaoxiao

p.s. attached is the sample context-test, with logo.gif points to apache
logo, and html/logo.gif points to tomcat logo.

Re: Diff behaviors for relative-path resource mapping in TC4 and TC5

Posted by David Smith <dn...@cornell.edu>.
I haven't dealt with TC 4 in a long time.  I would think it's the
difference in how the user is forwarded to the resource.  An internal
forward leaves the browser to compute relative paths based on the
original request URI while an external forward offers the browser a new
request URI to compute relative paths against.  Best practice would be
to get the context path and then define the image source as an absolute
path from the server root: 

Assuming a webapp designed to servlet 2.4/jsp 1.2 spec (tomcat 5.0/5.5),
that would be <img src="${pageContext.request.contextPath}/logo.gif"/>

For a servlet 2.3/jsp1.1 spec (tomcat 4), that might be <img
src="<%=request.getContextPath()%>/welcome/logo.gif" />

This method leaves the flexibility to have the same webapp in different
context while making sure the resource path is always computed correctly
regardless of forward method.

--David

Xiao Xiao wrote:

> Xiao Xiao wrote:
>
>> Hi,
>>    Saying i have the following web-app structure:
>>       WEB-INF/web.xml
>>       html/logo.gif
>>       html/welcome.html
>>       logo.gif
>>    in the web.xml, html/welcome.html is defined as one of the
>> welcome-file, which includes an image defined as src="./logo.gif". My
>> question is which logo will be shown when i try to access web-app?
>> Seems TC4  ( 4.1.31) and TC5 (5.1.12) handle this differently.
>>    In TC5, the request is mapped to html/welcome.html, but the
>> context is still at the root-level, so the logo.gif at root level is
>> returned; while in TC4, it will redirect to html/welcome.html, with
>> the context changes to html as well -- so html/logo.gif is returned.
>> For me, it seems TC5 makes more senses, but anyone can help me
>> confirm this? (as is it a TC4 bug? a change in the spec? etc?)
>>    Thanks.
>> xiaoxiao
>>  
>> p.s. attached is the sample context-test, with logo.gif points to
>> apache logo, and html/logo.gif points to tomcat logo.
>>          
>
> Hi,
>   Can anybody give any feedback?
>   Thanks a lot!
> xiaoxiao
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Diff behaviors for relative-path resource mapping in TC4 and TC5

Posted by Xiao Xiao <xi...@gmail.com>.
Xiao Xiao wrote:
> Hi,
>    Saying i have the following web-app structure:
>       WEB-INF/web.xml
>       html/logo.gif
>       html/welcome.html
>       logo.gif
>    in the web.xml, html/welcome.html is defined as one of the 
> welcome-file, which includes an image defined as src="./logo.gif". My 
> question is which logo will be shown when i try to access web-app? 
> Seems TC4  ( 4.1.31) and TC5 (5.1.12) handle this differently.
>    In TC5, the request is mapped to html/welcome.html, but the context 
> is still at the root-level, so the logo.gif at root level is returned; 
> while in TC4, it will redirect to html/welcome.html, with the context 
> changes to html as well -- so html/logo.gif is returned. For me, it 
> seems TC5 makes more senses, but anyone can help me confirm this? (as 
> is it a TC4 bug? a change in the spec? etc?)
>    Thanks.
> xiaoxiao
>  
> p.s. attached is the sample context-test, with logo.gif points to 
> apache logo, and html/logo.gif points to tomcat logo.
>     
>   
>    
Hi,
   Can anybody give any feedback?
   Thanks a lot!
xiaoxiao

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Diff behaviors for relative-path resource mapping in TC4 and TC5

Posted by Xiao Xiao <xi...@gmail.com>.
Xiao Xiao wrote:
> Hi,
>    Saying i have the following web-app structure:
>       WEB-INF/web.xml
>       html/logo.gif
>       html/welcome.html
>       logo.gif
>    in the web.xml, html/welcome.html is defined as one of the 
> welcome-file, which includes an image defined as src="./logo.gif". My 
> question is which logo will be shown when i try to access web-app? 
> Seems TC4  ( 4.1.31) and TC5 (5.1.12) handle this differently.
>    In TC5, the request is mapped to html/welcome.html, but the context 
> is still at the root-level, so the logo.gif at root level is returned; 
> while in TC4, it will redirect to html/welcome.html, with the context 
> changes to html as well -- so html/logo.gif is returned. For me, it 
> seems TC5 makes more senses, but anyone can help me confirm this? (as 
> is it a TC4 bug? a change in the spec? etc?)
>    Thanks.
> xiaoxiao
>  
> p.s. attached is the sample context-test, with logo.gif points to 
> apache logo, and html/logo.gif points to tomcat logo.
>     
>   
>    
Hi,
   Any feedback for this issue?
   Thanks.
xiaoxiao

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org