Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 8112 invoked from network); 7 Aug 2006 08:21:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 7 Aug 2006 08:21:16 -0000 Received: (qmail 12039 invoked by uid 500); 7 Aug 2006 08:21:05 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 10983 invoked by uid 500); 7 Aug 2006 08:21:02 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 10971 invoked by uid 99); 7 Aug 2006 08:21:02 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Aug 2006 01:21:02 -0700 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of kazazic@gmail.com designates 66.249.92.175 as permitted sender) Received: from [66.249.92.175] (HELO ug-out-1314.google.com) (66.249.92.175) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Aug 2006 01:20:55 -0700 Received: by ug-out-1314.google.com with SMTP id u40so2277ugc for ; Mon, 07 Aug 2006 01:20:28 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=TS0e1LmwmgoUrZdh216JJvgBEbq92WjA8ipmayVZhvbWAwGiJSnOAp1TGaNMjRS1ccaX2OKzt9BJtNt0FLanhlh9dthmdn2XeAueC0dyHqd833pOOjiVFi0icwKEfggw9tkRYwLhf+EIvo9OByYN/xAip/c+Rxsv/Dnfw6V38b0= Received: by 10.66.221.19 with SMTP id t19mr7708847ugg; Mon, 07 Aug 2006 01:20:28 -0700 (PDT) Received: by 10.66.245.16 with HTTP; Mon, 7 Aug 2006 01:20:28 -0700 (PDT) Message-ID: Date: Mon, 7 Aug 2006 10:20:28 +0200 From: "Almir Kazazic" To: "Tomcat Users List" Subject: Re: Writing files accessible from a browser In-Reply-To: <44D6F1EC.8090000@chem.usyd.edu.au> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <44D6DA5A.1060208@chem.usyd.edu.au> <44D6E13B.3080906@chem.usyd.edu.au> <44D6E6CF.7070701@chem.usyd.edu.au> <44D6EDAE.4040906@chem.usyd.edu.au> <44D6F1EC.8090000@chem.usyd.edu.au> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Oh I see, something like that , i do not think taht this will work String imagePath = path+"../imagedir"; but you will have to either convert path to instance of directory object, or chop of the end by some string functions , using String imagePath = path+"../imagedir"; as path works for browser but I am not shure about filesystem regards On 8/7/06, Romain Quilici wrote: > I agree with you, but > getContext().getRealPath("/"), will return the path to my webapp root, > so it means I am going to create my image dir under my webapp, which is > fine unless my application is deployed in a war file. > In such case I won't be able to write in my webapp. > Maybe using > String path = getContext().getRealPath("/"); > then > String imagePath = path+"../imagedir"; would work so I am writting in a > separate directory outside my webapp. In case I use war file, this > solution might still works > Regards > > Almir Kazazic wrote: > > Hi, > > > > to avoid using absolut paths you can find that out on runtime by > > > > getContext().getRealPath("/") - will return your path to the root > > > > regards > > > > > > On 8/7/06, Romain Quilici wrote: > >> Hi, > >> Hope I will be clear enough: > >> > >> One part of my web application receives encodes stream that it has to > >> convert to jpg images. When an image is written on the server, it > >> notifies a Servlet which pushes the name (or the url) of the newly > >> generated image inside client browser(thanks to pushlets technology). > >> The Servlet can only push a String (Pushlets requirements). > >> > >> So my problem is where can I write the images, so they can be accessible > >> by a URL. One easy solution, the one I use for testing, is to hardcode > >> in my webapp the directory where the images are written. > >> For instance TOMCAT_HOME\webapps\frames\, > >> and in my jsp to have in my jsp. > >> >> > >> >> Indeed I don't want to modify these values if I decide Tomcat to > >> run on > >> >> another port, or to install Tomcat in another directory or even > >> OS. That > >> >> is why I am looking for an approach using > >> >> the webapp context, so I don't have to worry about the OS, or the > >> port, > >> >> or whatever configuration. > >> >> Anyway thanks for your help > >> >> Regards > >> >> Romain > >> >> > >> >> Li wrote: > >> >> > Hi, > >> >> > > >> >> > Here are few steps of achieving it (just tested, and it works): > >> >> > 1. use FileOutputStream or any output streaming object to write a > >> >> > image file > >> >> > into the directory > >> >> > in Windows, the path string should look like: > >> >> > "c:\apache_home\httpdocs\images\1.jpg" > >> >> > in unix/linux, the path should look like > >> >> > $APACHE_HOME\httpdocs\images\1.jpg" > >> >> > (assume, you had defined APACHE_HOME, make sure the images folder > >> >> > is read/write > >> >> > only for the user/group that runs tomcat > >> >> > 2. Make sure apache is on ... > >> >> > 3. in your jsp: use > >> >> > e.g. click to view > >> >> > > >> >> > > >> >> > Wish it helps > >> >> > > >> >> > On 8/7/06, Romain Quilici wrote: > >> >> >> Thanks for the answer, > >> >> >> this solution was part of my investigation, and was actually the > >> >> first > >> >> >> idea I had. > >> >> >> The problem with this approach is I don't know how to access the > >> >> >> /image_dir/ from within my web application. > >> >> >> Maybe using something like > >> >> >> String path = servletContext.getRealPath("/"); > >> >> >> String imagePath = path+"../image_dir/" > >> >> >> and use the imagePath to create my images, then in my jsp > >> >> something like > >> >> >> > >> >> >> > >> >> >> But I am not sure this approach works in all configurations, > >> >> >> particularly if my webapp is deployed inside a war. > >> >> >> > >> >> >> Thanks > >> >> >> Romain > >> >> >> > >> >> >> Li wrote: > >> >> >> > if you have apache server, you can write file to its home > >> dir, and > >> >> >> > then use > >> >> >> > http:////image_name.suffix to view. > >> >> >> > > >> >> >> > On 8/7/06, Romain Quilici wrote: > >> >> >> >> Hi all, > >> >> >> >> I have been reading several messages about writing files inside > >> >> a web > >> >> >> >> application, but I found no answer regarding my problem. > >> >> >> >> > >> >> >> >> I need to write files on the file system that can be accessible > >> >> >> with a > >> >> >> >> browser(I write images). > >> >> >> >> > >> >> >> >> - The most reliable solution I found was to use the webapp's > >> tmp > >> >> >> >> directory, unfortunately this directory is not accessible with > >> >> a URL. > >> >> >> >> > >> >> >> >> - Another solution would be to write these images under my > >> webapp > >> >> >> >> root(or in another place under my webapp). But it seems that > >> this > >> >> >> >> approach does not work with webapps deployed in a war file. > >> >> >> >> Indeed you cannot write inside wars like this. > >> >> >> >> > >> >> >> >> I don't want to rely on some hardcoded solutions. There is > >> >> still the > >> >> >> >> possibility to pass the absolute path to the directory > >> (let's say > >> >> >> >> TOMCAT_HOME/webapps/myimages/) and later, use inside my JSP > >> >> >> >> , but I think > >> >> this > >> >> >> >> solution won't work in many configurations > >> >> >> >> > >> >> >> >> Thanks a lot for your help > >> >> >> >> Regards > >> >> >> >> Romain > >> >> >> >> > >> >> >> >> > >> >> >> >> > >> >> >> >> > >> >> >> >> > >> >> --------------------------------------------------------------------- > >> >> >> >> 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 > >> >> >> > >> >> >> > >> >> > > >> >> > > >> >> > >> >> > >> >> > >> >> --------------------------------------------------------------------- > >> >> 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 > >> > >> > > > > --------------------------------------------------------------------- > > 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 > > --------------------------------------------------------------------- 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