You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ritesh399 <ri...@gmail.com> on 2009/07/21 07:54:51 UTC

providing downloading functionality for a file which is on disk

Hi all
I am developing a web application using jsp and want to provide some links
for a user to download data. The data is not in web application's
directory(somewhere else on disk)
Can I provide a direct link to that data file ?



Thanks
Ritesh 
-- 
View this message in context: http://www.nabble.com/providing-downloading-functionality-for-a-file-which-is-on-disk-tp24582115p24582115.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


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


Re: providing downloading functionality for a file which is on disk

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lanxiazhi,

On 7/21/2009 7:52 AM, lanxiazhi wrote:
> I don't have a linux at hand to prove this idea:
> if you're deploy your app in linux ,maybe you can use a soft link to that
> directory ,and put the link under your webapp's dir.
> hope that will help.

There's also MKLINK on Windows Vista and higher.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkpozhYACgkQ9CaO5/Lv0PD5MACgiXHI3GEq45OF+i1xJxxzqrji
IioAnRHhyXjUTq7ipH8SMtTd6npRMZGE
=MvmO
-----END PGP SIGNATURE-----

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


Re: providing downloading functionality for a file which is on disk

Posted by lanxiazhi <la...@gmail.com>.
I don't have a linux at hand to prove this idea:
if you're deploy your app in linux ,maybe you can use a soft link to that
directory ,and put the link under your webapp's dir.
hope that will help.
thanks.
lanxiazhi
2009/7/21 Kham Mulman <km...@gmail.com>

> you can.
>
> for instance,
>
> File file = new File("C:\\temp\\downloadfilename.csv");
> FileInputStream fileIn = new FileInputStream(file);
> ServletOutputStream out = response.getOutputStream();
>
> byte[] outputByte = new byte[4096];
> //copy binary contect to output stream
> while(fileIn.read(outputByte, 0, 4096) != -1)
> {
>        out.write(outputByte, 0, 4096);
> }
> fileIn.close();
>
>
>
>
>
> On Tue, Jul 21, 2009 at 2:54 PM, Ritesh399 <ri...@gmail.com> wrote:
>
> >
> > Hi all
> > I am developing a web application using jsp and want to provide some
> links
> > for a user to download data. The data is not in web application's
> > directory(somewhere else on disk)
> > Can I provide a direct link to that data file ?
> >
> >
> >
> > Thanks
> > Ritesh
> > --
> > View this message in context:
> >
> http://www.nabble.com/providing-downloading-functionality-for-a-file-which-is-on-disk-tp24582115p24582115.html
> > Sent from the Tomcat - User mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
>

Re: providing downloading functionality for a file which is on disk

Posted by Kham Mulman <km...@gmail.com>.
you can.

for instance,

File file = new File("C:\\temp\\downloadfilename.csv");
FileInputStream fileIn = new FileInputStream(file);
ServletOutputStream out = response.getOutputStream();

byte[] outputByte = new byte[4096];
//copy binary contect to output stream
while(fileIn.read(outputByte, 0, 4096) != -1)
{
	out.write(outputByte, 0, 4096);
}
fileIn.close();





On Tue, Jul 21, 2009 at 2:54 PM, Ritesh399 <ri...@gmail.com> wrote:

>
> Hi all
> I am developing a web application using jsp and want to provide some links
> for a user to download data. The data is not in web application's
> directory(somewhere else on disk)
> Can I provide a direct link to that data file ?
>
>
>
> Thanks
> Ritesh
> --
> View this message in context:
> http://www.nabble.com/providing-downloading-functionality-for-a-file-which-is-on-disk-tp24582115p24582115.html
> Sent from the Tomcat - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: providing downloading functionality for a file which is on disk

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Michael Ludwig [mailto:mlu@as-guides.com]
> Subject: Re: providing downloading functionality for a file which is on
> disk
> 
> Is there a way of including a second context with a web 
> application in a similarly convenient way?

No.  The servlet spec expects webapps to be independent of each other, and Tomcat follows that expectation.  You have to install the two webapps separately.

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


Re: providing downloading functionality for a file which is on disk

Posted by Michael Ludwig <ml...@as-guides.com>.
Caldarale, Charles R schrieb:

> If you don't mind providing direct access to the downloadable area,
> one easy way to provide this is to place a <Context> element in
> conf/Catalina/[host]/[dlink].xml, where [dlink] is the URL link you
> want for the downloadable files.  Within the <Context> element, place
> a docBase attribute that points to the directory that downloads occur
> from.  No programming required.

> <Context docBase="/usr/myName/downloads"/>
>
> and it would be placed in conf/Catalina/localhost/files.xml.

That's convenient. I tried including an additional Context file named
import.xml with an unrelated web-app, thinking that by some chance it
might result in a second context being configured.

<Context path="import" docBase="C:\MILU\data\ASV-DS"/>

(I'm aware you should never set either @path or @docBase on
"META-INF/context.xml" as they are inferred, but the above was
meant for a different context needing these parameters.)

----------------------------------
M:\WORKSPACE\XPGJ\WEBCONTENT
│
├───META-INF
│       context.xml
│       import.xml
│       MANIFEST.MF
│
└───WEB-INF
     │   web.xml
----------------------------------

As I suspected, no second context gets configured. Is there a way
of including a second context with a web application in a similarly
convenient way?

Michael Ludwig

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


RE: providing downloading functionality for a file which is on disk

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Ritesh399 [mailto:ritesh399@gmail.com]
> Subject: providing downloading functionality for a file which is on
> disk
> 
> I am developing a web application using jsp and want to provide some
> links for a user to download data. The data is not in web application's
> directory(somewhere else on disk)

If you don't mind providing direct access to the downloadable area, one easy way to provide this is to place a <Context> element in conf/Catalina/[host]/[dlink].xml, where [dlink] is the URL link you want for the downloadable files.  Within the <Context> element, place a docBase attribute that points to the directory that downloads occur from.  No programming required.

For example, if using the default <Host> element and the downloadable files are in /usr/myName/downloads and you want the URL pattern for accessing these to be http://myhost.com/files/*.*, your <Context> element would look like this:

<Context docBase="/usr/myName/downloads"/>

and it would be placed in conf/Catalina/localhost/files.xml.

 - 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