tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@informatiefabriek.nl
Subject RE: Show files on filesystem
Date Wed, 16 Apr 2003 13:34:15 GMT
Hehe ;-)

I know how java IO works... 
I have coded the following:

-----------------------
File f = new File(valueObj.getPath());
InputStream is = new BufferedInputStream(new 
FileInputStream(valueObj.getPath()));
OutputStream os = response.getOutputStream();
response.setContentType("application/pdf");
int b;
while ((b = is.read()) != -1) {
        os.write(b);
}
os.flush();
os.close();
is.close(); 
----------------------------

I'm just wondering if this method is efficient. Because the file first has 
to be read completely and then written to the output stream.

Thanks,

Harm.




"James Lewis" <james.lewis@goodtechnology.com> 
04/16/2003 03:20 PM
Please respond to
"Tomcat Users List" <tomcat-user@jakarta.apache.org>


To
"Tomcat Users List" <tomcat-user@jakarta.apache.org>
cc

Subject
RE: Show files on filesystem






yes :p

Umm, you cold have a look at the API javadocs for io classes, or
alternatively the tutorial on the sun site is pretty good.

http://java.sun.com/docs/books/tutorial/essential/io/index.html (for a 
java
IO tutorial)

and:

http://java.sun.com/products/servlet/2.2/javadoc/ for the
ServletOutputStream doc

All fairly straightforward.

james






> -----Original Message-----
> From: harm@informatiefabriek.nl [mailto:harm@informatiefabriek.nl]
> Sent: 16 April 2003 14:08
> To: Tomcat Users List
> Subject: Re: Show files on filesystem
>
>
> Thanks for your reply....
>
> I think I should go with the second option. Do have an example on how to
> do this?
>
> Thanks,
>
> Harm.
>
>
>
>
> "Andre E. Bar'yudin" <baryudin@pob.huji.ac.il>
> 04/16/2003 11:06 AM
> Please respond to
> "Tomcat Users List" <tomcat-user@jakarta.apache.org>
>
>
> To
> Tomcat Users List <tomcat-user@jakarta.apache.org>
> cc
>
> Subject
> Re: Show files on filesystem
>
>
>
>
>
>
> On Срд, Апр 16, 2003 at 10:35:33 +0200, harm@informatiefabriek.nl wrote:
> > Hi all,
> >
> > I have Tomcat 4.1 running on Linux.
> >
> > I have installed Tomcat in /usr/java/jakarta-tomcat/
> >
> > In my web application I would like to offer my user the possibilty to
> view
> > PDF files stored elsewhere on the filesystem.
> > The PDF's are in /var/om/pdfs
> >
> > In my web application I have a link the user can click. When he
> does so,
> a
> > PDF should be downloaded or displayed in the browser.
> >
> > How can I achieve this using only Tomcat?
>
> The simpliest way is to make a link to your PDF files.  To the files
> themselves you may make a hard link, pointing somewhere under the Tomcat
> directory hierarchy.  To link directories, you'll have to use sybmolic
> links, which might require some configuration with newer versions of
> Tomcat.
>
> Another, more generic approach would be to use the standard Java IO API
> to read the file from its original location and then just write it out
> to the servlet's output stream.
>
> Regards,
>
> Andre.
>
> --
> Andre E. Bar'yudin
> Phone: (972)-54-882-026       ICQ: 48036924
> Home page: http://www.cs.huji.ac.il/~baryudin/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>


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



Mime
View raw message