tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier ...@ice-sa.com>
Subject Re: resource file location (was: Logo file location)
Date Mon, 14 Dec 2009 23:42:20 GMT
Caldarale, Charles R wrote:
>> From: André Warnier [mailto:aw@ice-sa.com]
>> Subject: resource file location (was: Logo file location)
>>
>> The trouble is, it does not really explain what is meant by a "path" in
>> that context, and some of the other method descriptions on the same
>> page introduce a slight doubt.
> 
> Sure it does:
> 
> "The path must begin with a "/" and is interpreted as relative to the current context
root.
> 
> "This method allows the servlet container to make a resource available to servlets from
any source. Resources can be located on a local or remote file system, in a database, or in
a .war file.
> 
> "The servlet container must implement the URL handlers and URLConnection objects that
are necessary to access the resource."
> 
> The path parameter is clearly a URL for any resource in the domain of the context.  What
the URL actually maps to depends on the configuration of the webapp and container.
> 
>> If it is a real absolute file path on the hosting system
> 
> There is no requirement and certainly no guarantee that the host even has a file system.
> 
>> if on that system CATALINA_BASE is "/srv/tomcat/", then supposedly the
>> parameter needs to be specified as
>> <init-param>
>>    <param-name>thelogo</param-name>
>>   <param-value>/srv/tomcat/webapps/myapp/logos/mylogo.jpg</param-value>
>> </init-param>
> 
> Nope.  Read the API spec again: "interpreted as relative to the current context root."
 The proper setting is just <param-value>/logos/mylogo.jpg</param-value>.
> 
>> That seems to me in flagrant contradiction of the "encapsulation" ideal
>> of a webapp and even of Java.
> 
> It would be, which is why the spec doesn't do it that way.
> 
>> and then used code like
>>
>> InputStream logo_stream =
>> ctx.getResourceAsStream(ctx.getRealPath(ctx.getInitParameter('thelogo')
>> ));
> 
> Again, getRealPath() should NEVER (well, almost never) be used, since there's no requirement
for it to return anything useful.
> 
>> So what is one to do, if one wants not to have to change the content of
>> one's war file for each target host, but still allow the webapp to find
>> and read the logo ?
> 
> You don't - you just have to read the spec correctly, and not ignore the definition of
the parameter.
> 
Chuck, Chris,

Ok, I get it now.  I just read the Method Summary part of that page, 
never scrolled down to the Method Detail descriptions, so I missed the 
very clear definition of "path".
Mea culpa.
Thanks for showing me the errors of my ways.
And I swear that I'll never use getRealPath().





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


Mime
View raw message