aspose file tools*
The moose likes Tomcat and the fly likes Download option from Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Download option from Tomcat" Watch "Download option from Tomcat" New topic
Author

Download option from Tomcat

Kalyan Anand
Ranch Hand

Joined: Feb 07, 2007
Posts: 194
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

Try to stream PDF from Servlet.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42951
    
  72
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

Joined: Jun 25, 2001
Posts: 16308
    
  22

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Download option from Tomcat