You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by ed...@yahoo.com on 2005/04/02 05:23:17 UTC

tomcat 5.5/win & loading external image files

i need to load a bunch of image files located outside my exploded war
file.  for example, say that the images live here 
 
|---c:\myimages
|-----------\app
|-----------------\promotions
|-------------------------\images
 
& my app is under 
 
|---c:\tomcat5.5
|----------\webapps
|--------------------\myapp.  
 
the img links are written out dynamically based on an init-param in the
web.xml & javabeans.   the result is that i can get a valid path to the
image resouce looking at the html, but cannot actually load the image. 
 
does anyone know if that's possible on the windows platform (win2k
server)?  
 
 
thanks

Re: tomcat 5.5/win & loading external image files

Posted by Parsons Technical Services <pa...@earthlink.net>.
Tomcat cannot serve up files outside the root of the app. To do what you 
want requires a work around that has been discussed and debated on this list 
several times. If this is what you have to have, then write a servlet that 
responds to a pattern setup for the images 
(http://www.yoursite.com/yourapp/imagefiles/mypic.jpg). Map the servlet to 
answer for any /imagefiles/* request. Then have the servlet parse the file 
name, read from disk (the directory you want) and serve the file out in 
response to the request.

Other options include using a database to store the images or putting the 
images in the app. One other suggestion was to have an app just for images.

It really is just what fits your needs the best and the pros and cons of 
each. IE You can't move this app to a Linux box without a rewrite.

Doug


----- Original Message ----- 
From: <ed...@yahoo.com>
To: <to...@jakarta.apache.org>
Sent: Friday, April 01, 2005 10:23 PM
Subject: tomcat 5.5/win & loading external image files


>i need to load a bunch of image files located outside my exploded war
> file.  for example, say that the images live here
>
> |---c:\myimages
> |-----------\app
> |-----------------\promotions
> |-------------------------\images
>
> & my app is under
>
> |---c:\tomcat5.5
> |----------\webapps
> |--------------------\myapp.
>
> the img links are written out dynamically based on an init-param in the
> web.xml & javabeans.   the result is that i can get a valid path to the
> image resouce looking at the html, but cannot actually load the image.
>
> does anyone know if that's possible on the windows platform (win2k
> server)?
>
>
> thanks
> 



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


Re: tomcat 5.5/win & loading external image files

Posted by Anto Paul <an...@gmail.com>.
On Apr 2, 2005 8:53 AM, edwardeguard-cosita@yahoo.com
<ed...@yahoo.com> wrote:
> i need to load a bunch of image files located outside my exploded war
> file.  for example, say that the images live here
> 
> |---c:\myimages
> |-----------\app
> |-----------------\promotions
> |-------------------------\images
> 
> & my app is under
> 
> |---c:\tomcat5.5
> |----------\webapps
> |--------------------\myapp.
> 
> the img links are written out dynamically based on an init-param in the
> web.xml & javabeans.   the result is that i can get a valid path to the
> image resouce looking at the html, but cannot actually load the image.
> 
> does anyone know if that's possible on the windows platform (win2k
> server)?
> 
> thanks
> 
> 

A relative link will work if it is inside the web application root. 
    If you want to load external images write a Servlet to which the
path or name of the image file is passed as an argument and the
Servlet reads the file using ServletContext.getResourceAsStream() and
write it to the OutputStream returned by the
response.getOutputStream(). Dont forget to set the appropriate MIME
type for content type.

-- 
Anto Paul
Benchmark Softech
www.benchmarksoft.com

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