• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Down loading a file using Servlet

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
My requirement is that I need to provide down load option to a file so that I can save it in my local directory using Servlet.
Could u suggest me some approach to do this.
Thanks in Advace
Vasu.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to try the search functionality to look for similar questions in this forum. (andget threads like this one)
Basically, you can open a InputStream to the file and dump it the OutputStream to the client. The only tricky bit is usually setting the content-type.
"champ",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please re-register and select a new name which meets the requirements.
You have 6 posts under this name, if you don't change it, it is likely your account will be locked
Thanks.
Dave
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i have done something like this in the past. basically we gave the usere a link to download their report data as a csv file.
basically you just provide a hyperlink to the file eg..
<a href="data.csv">
you then configure the mime type for csv to be application/octet-stream
this means that when you cloick on the link, your browser will prompt the user to save the file.
if you have a dynamic file such as some repor tdata for that particular user, you could have the link go to a servelt, that could create the fiel and then redirect (i'm not sure about forward) the request onto the newly created csv file.
hope this helps - dean
 
dean tomlinson
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi champ,
with regards to the above. if you specify your link to be aservelt , that can then condstruct the file for downl,oad, you need to do response.sendredirect not forward.
good luck - cheers, dean
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic