• Post Reply Bookmark Topic Watch Topic
  • New Topic

Down loading a file using Servlet  RSS feed

 
vasu devan
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.
 
David O'Meara
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
 
dean tomlinson
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!