tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Li <ampyx...@gmail.com>
Subject Re: Writing files accessible from a browser
Date Mon, 07 Aug 2006 06:56:09 GMT
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. <a href="http://yourdomain/images/1.jpg">click to view</a>


Wish it helps

On 8/7/06, Romain Quilici <r.quilici@chem.usyd.edu.au> 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
> <request.getContextPath()/../image_dir/image1.jpg>
>
> 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://<youdomain>/<image_dir>/image_name.suffix to view.
> >
> > On 8/7/06, Romain Quilici <r.quilici@chem.usyd.edu.au> 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
> >> <request.getContextPath()/../myimages/image1.jpg>, 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
>
>


-- 
When we invent time, we invent death.

---------------------------------------------------------------------
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


Mime
View raw message