File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes code for file download Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "code for file download" Watch "code for file download" New topic

code for file download

Udit Manektala
Ranch Hand

Joined: Sep 17, 2006
Posts: 30
The code below fetches me the file I intend to download using the servlet but in the browser, the file is received (downloaded) as POTD ( with no file extension) instead of test.jar

Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
one possible solution would be to have users request:

and map requests for test.jar to your POTD servlet.

Fun programming etcetera!
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63059

Investigate the "content-disposition" header.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

See the JspAndExcel example in the JSP FAQ section of this site for sample code that uses the Content-Disposition header to do this.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: code for file download
It's not a secret anymore!