Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Displaying the File Download dialog box

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm trying to allow users of the site to be able to download a file (e.g Calendar Image file) when they click the Download link.

I have the url and have put it inside the tag
<a href="<%=URL%>">Download</a>, but this is opening the image in the window.

I want it to open the File Download dialog box with the options to Save or Open the File.

I'm doing this in a jsp within a portlet.
Your help will be greatly appreciated.

Kind Regards,
Siphiwe Madi
[ July 23, 2008: Message edited by: Bear Bibeault ]
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know how to display that dialog box
But I think this is because the browser knows of the image file. If you put something else in the href like say a .xyz file then the browser will show the dialog you are talking of.

Same thing applies to PDF documents when you have a reader in place, the browser opens the file opens it or displays the dialog you are talking of.


Hope this helps
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
portal framework you are using may stop/override download popup window. If i am not wrong every window is a part of framework once you integrate your application with framework.I have faced the same problem once and i have a provision to specify not to dispaly pop up window in portal framework as below and that's solves the problem.
<a href="url?...&pCpslayout=false">payload</a>
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't force browsers to do anything but, the best way to convice one to prompt the user with a Save/Open dialog box is to set the content type to something that the browser wouldn't have an association for.

When you do this, if you also set the Content-Disposition header, you can suggest that the browser use a particular file name when saving and (if the contentType is known, suggest that the browser not try to open the associated application inline but instead prompt the user with the save/open dialog box.

In our JSP FAQ under JspAndExcel there is an example that sets both the Content-Type and the Content-Disposition headers.
 
pie. 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