Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Download option from Tomcat

 
Kalyan Anand
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a html where I used href to point pdfs... these pdfs are placed under webpplication folder in tomcat.

when the user clicks on this href link... the pdf content is shown in the browser with some junk chars.... all I want is when user clicks on the href... it should ask the user to save/open dialog.. the option which we generally see on any website in downloading pdfs.

any help ?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SimpleStream example in the http://faq.javaranch.com/java/CodeBarnServlets shows how to stream binary files from a servlet.

You'll also need to set the Content-Disposition header as an attachment with a file name; something like:
response.setHeader("Content-Disposition", "attachment; filename=\"foobar.pdf\"");
 
Tim Holloway
Bartender
Posts: 18423
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, don't store writeable files (PDF or otherwise) in the web application folder. It can cost you significantly. Read-only files are fine, but if you upload files into the webapp directory, it won't always work and you may end up like I did and get zapped when someone upgrades the webapp and the data files are get erased.
 
We noticed he had no friends. So we gave him this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!