• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Multipart downloads

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi

Users in our app can currently download a simple text file by clicking the appropriate button on a JSF page, the code snippet for which is shown below.
After their browser pops up the download window and the download is successful, their browser shows the same page they had before they clicked on the button.

Is it possible to send a multipart response back to the browser - containing the download, and the html for the next page they should see after the download?


--------------------- cleaned snippet for simple download, which works fine as it is -------------------------------
String exportedReport = generateReport();
bytes[] exportedBytes = exportedReport.getBytes();
String filename = "yourReport.txt";
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
response.setContentType("text/plain");
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
response.setContentLength(exportedBytes.length);
try {
response.getOutputStream().write(exportedBytes);
response.getOutputStream().flush();
//response.getOutputStream().close();
context.responseComplete();
}
 
Saloon Keeper
Posts: 28477
210
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
Unfortunately not. An HTTP response is basically just one "file". So if you send a document as a response, there's no place to hold the link. Web pages sidestep that problem by having embedded links to things like images which then download as separate request/response items, but that works because the HTML page renderer in the browser is designed to sense those links and make the requests. The general (non-HTML) processor doesn't do that.

You can return an HTML page that has multiple document links on it, which isn't the same thing, but at least it works. Or for that matter, you could simply have the server email a multi-part MIME document, although even there someone has to manually select where the different files in the email get broken out and under what names.
 
Look! It's Leonardo da Vinci! And he brought a tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic