• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to download a zip file

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

I would like to download a zip file from a constant location on the server to the user (with a dialog).

I wrote the following code but it doesn't display it:

How can i open a save dialog? is there a util for that?
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try changing the response content type to "application/zip" and also response transfer encoding to binary... it should prompt you with the save/open dialog.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using context.responseComplete(); after out.close();
 
Ranch Hand
Posts: 92
Mac Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's been a long time now, but it does not hurt asking...

Have this be resolved?

I'm with a similar problem, the SaveAs dialog box is not displayed in the browser, and I'm already using

context.responseComplete();

in my code.

Jordan, if you're still around and remember how to solve this, I'd be glad to have your thoughts.

I've been working on this and counting on this thread to share what's happening here: https://coderanch.com/t/555081/JSF/java/response-setContentType-application-download-not#2518376

Thanks in advance!
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use JSF to generate non-HTML content.

JSF is not an all-or-nothing architecture. A JSF app can also contain servlets, traditional JSPs, and even Struts code.

The power of JSF is that allows you to manage HTML content (especially form content) easily. It does that by assuming total control over the HttpResponse and its output stream, however, and you inject your own low-level efforts at your peril.

It's a lot safer, cleaner, and simpler to provide the ZIP download from a servlet that to try and force JSF to do it.

There's a related thread on this forum where I've discussed similar issues.
 
Ajeeth Kumar
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Marcos Silvestri wrote:It's been a long time now, but it does not hurt asking...

Have this be resolved?

Jordan, if you're still around and remember how to solve this, I'd be glad to have your thoughts.

I've been working on this and counting on this thread to share what's happening here: https://coderanch.com/t/555081/JSF/java/response-setContentType-application-download-not#2518376

Thanks in advance!



Are you still facing issues or is it resolved?

The best solution that worked for me is to stop adding the response content behaviour manipulations in JSF.
Try adding response.complete and just do a flush before closing the streams. No need to use ZipOutput streams. Use buffer streams only if you are planning on sending huge data(more than 2 MB/4 MB approx)
 
Marcos Silvestri
Ranch Hand
Posts: 92
Mac Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks for the answer Ajeeth, but I'm no longer dealing with that.

Thanks anyway
 
reply
    Bookmark Topic Watch Topic
  • New Topic