• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Download option from Tomcat

 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to stream PDF from Servlet.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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\"");
 
Saloon Keeper
Posts: 28720
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic