aspose file tools*
The moose likes JSP and the fly likes How to provide download option on href link? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to provide download option on href link?" Watch "How to provide download option on href link?" New topic
Author

How to provide download option on href link?

pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 413

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.


Pawan Chopra
SCJP - DuMmIeS mInD
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Aug 03, 2008
Posts: 9313
    
  17

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 ]


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 413

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

Joined: Oct 08, 2006
Posts: 2458
Certainly. You would also have noticed it if you have read the code comments.
 
 
subject: How to provide download option on href link?