• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Download option from Tomcat

 
Kalyan Anand
Ranch Hand
Posts: 194
  • 0
  • 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: 2904
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to stream PDF from Servlet.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • 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
Saloon Keeper
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic