This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Down loading a file using Servlet

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
 
Doe, a deer, a female deer. Ray, a pockeful of sun. Me, a name, I call my tiny ad ...
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic