• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to provide download option on href link?

 
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am using href="/jsptreeexample/archive/Year2008/month08/date16/Off-Portal_4w_20-Jan-2009.pdf in jsp. When I am clcking on link its opening that pdf file in browser only. Is there any way to show download option? I saw its happening because of browser settings but I want to show download option without changing my browser settings. Thanks in advance.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let it point to some servlet which writes the PDF file to the outputstream of the response and, importantingly, sets the content disposition header to 'attachment'. This will cause the webbrowser pop a 'save as' dialogue (the 'download option' as you call yourself).

You may get some ideas out of this: http://balusc.blogspot.com/2007/07/fileservlet.html
 
Sheriff
Posts: 9689
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

pawan chopra wrote:I saw its happening because of browser settings but I want to show download option without changing my browser settings.



If you know that it's because of your browser settings, then just change the settings. The other way is to change the content type of the response but since you have a direct link of the file, so that is also not possible I think...

[Beaten to the explanation by Bauke ! Seems like there is a lot of information on you blog Bauke ]
 
pawan chopra
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks allot Bauke, Well I must say your blog rocks!! . Great work. Well just one question can I use that servlet to access files inside WEB-INF?


 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Certainly. You would also have noticed it if you have read the code comments.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic