• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to provide download option on href link?

 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • 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.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • 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
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Certainly. You would also have noticed it if you have read the code comments.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic