tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Caldarale, Charles R" <Chuck.Caldar...@unisys.com>
Subject RE: storing images
Date Thu, 05 May 2011 18:56:21 GMT
> From: alexis [mailto:alzrck@gmail.com] 
> Subject: storing images

> So, i have to create the image on the servlet (done) , store 
> the image on the disk (done), and return the <img> tab also 
> done. Thing is, where im able to store the image from the 
> servlet im not able to read it from the jsp. 

As David suggests, java.io.tmpdir is probably a bit safer than /tmp, since you have some control
over that and it can be isolated from other programs running on the same box.

The real problem is how to retrieve the images once stored.  Tomcat normally uses its built-in
DefaultServlet to deliver static content, but that only works with files stored within a given
webapp (and you should never write into a webapp's deployment directory).

You have a couple of options:

1) Create a dummy webapp whose sole purpose is to provide a location for the dynamically generated
images.  Create some directory outside of Tomcat's file structure to hold the images, and
place a <Context> element in conf/Catalina/[host]/[dummyAppName].xml with a docBase
attribute (and nothing else) that points to that directory.  The <img> tags should refer
to [dummyAppName] as the URL for retrieving the images.

 - or -

2) Create a subclass of DefaultServlet that knows where you put the images, and direct image
references to it via the appropriate servlet-mapping in your WEB-INF/web.xml file.  Not sure
which methods of the DefaultServlet you'll have to override.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus
for use only by the intended recipient. If you received this in error, please contact the
sender and delete the e-mail and its attachments from all computers.


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


Mime
View raw message