tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier ...@ice-sa.com>
Subject Re: Logo file location
Date Mon, 14 Dec 2009 20:53:43 GMT
André Warnier wrote:
> David kerber wrote:
>> Caldarale, Charles R wrote:
>>>> From: David kerber [mailto:dckerber@verizon.net]
>>>> Subject: Logo file location
>>>>
>>>> In TC 5.5.x or 6.0.x, Where in my webapp folder structure should I put
>>>> a small .bmp file that I use for putting a logo on generated reports?
>>>
>>> Use ServletContext.getResourceAsStream() to retrieve the file, which 
>>> can be located pretty much wherever you want inside the webapp, even 
>>> under WEB-INF.
>>
>> Will it find it pretty much wherever I put it,
> 
> I don't think that this was what Chuck really meant above
> 
> 
>  or will I need to specify
>> the location?
> 
> Yeah, it is not so smart. You have to give it a clue.
> 
>>
> http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContext.html 
> 
> It seems that you need to specify the path.
> But I guess you could set this path as an <init-param> in the web.xml of 
> your webapp.
> 
Upon further examination of the spec page above, I would guess that a 
better way (more flexible) would be to specify the relative URI of your 
file as an <init-param> value, and then do a getRealPath() to convert 
that into a real path, and then call getResourceAsStream() to get a 
stream opened on it.
At least I presume that this is what they mean by "virtual path", in the 
getRealPath() explanation.

so, web.xml :

<webapp .......>
...
   <init-param>
     <param-name>thelogo</param-name>
     <param-value>/logos/printlogo.jpg</param-value>
   </init-param>

application :

    InputStream logo_stream = 
context.getResourceAsStream(context.getRealPath(context.getInitParm('thelogo')));

plus or minus some exception-catching stuff in case you messed up somewhere

and put your (readable) file in /webapps/mywebapp/logos/printlogo.jpg

Right, gurus ?




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


Mime
View raw message