Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to download a zip file

 
Jordan Smith
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • 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?
 
Ajeeth Kumar
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • 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.
 
Vinay Kaparthi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using context.responseComplete(); after out.close();
 
Marcos Silvestri
Ranch Hand
Posts: 62
Chrome Java Mac
  • Mark post as helpful
  • send pies
  • 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: http://www.coderanch.com/t/555081/JSF/java/response-setContentType-application-download-not#2518376

Thanks in advance!
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18276
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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: http://www.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: 62
Chrome Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Thanks anyway
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic