Content unavailable! (broken link)https://dynarocks.com/wiki/attach/PageHeader/interSULT-2.002.jpg

This page (revision-55) was last changed on 11-Mar-2016 22:39 by Dieter Käppel

This page was created on 12-Nov-2010 09:09 by Dieter Käppel

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Version Date Modified Size Author Changes ... Change note
55 11-Mar-2016 22:39 23 KB Dieter Käppel to previous
54 11-Mar-2016 22:39 23 KB Dieter Käppel to previous | to last
53 09-Jan-2014 11:04 23 KB Dieter Käppel to previous | to last
52 27-Jul-2013 13:25 23 KB Dieter Käppel to previous | to last
51 24-Jul-2013 19:50 23 KB Dieter Käppel to previous | to last
50 23-Jul-2013 08:35 23 KB Dieter Käppel to previous | to last
49 08-Jul-2013 19:14 21 KB Dieter Käppel to previous | to last
48 11-Jun-2013 12:50 20 KB Dieter Käppel to previous | to last
47 26-Apr-2013 11:13 19 KB Dieter Käppel to previous | to last
46 26-Apr-2013 11:11 18 KB Dieter Käppel to previous | to last
45 26-Apr-2013 07:42 16 KB Dieter Käppel to previous | to last
44 26-Feb-2013 13:12 16 KB Dieter Käppel to previous | to last
43 18-Dec-2012 12:30 16 KB Dieter Käppel to previous | to last
42 16-Dec-2012 21:18 16 KB Dieter Käppel to previous | to last
41 16-Dec-2012 14:25 15 KB Dieter Käppel to previous | to last

Difference between version and

At line 511 added 43 lines
!!!Download
Bei JSF ist im kein Download-Servlet erforderlich, es kann einfach über eine Action-Methode abgewickelt werden:
{{{
<h:commandLink value="#{fileUpload.filename}" action="#{fileUpload.download}"
rendered="#{fileUpload.file != null}"/>
}}}
Die zugehörige Action-Methode:
{{{
public void download() throws IOException {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
externalContext.setResponseContentType(mimeType);
externalContext.addResponseHeader("Content-Disposition", "attachment; filename=" + filename);
externalContext.setResponseContentLength(file.length);
OutputStream outputStream = externalContext.getResponseOutputStream();
outputStream.write(file);
FacesContext.getCurrentInstance().responseComplete();
}
}}}
__Erklärung:__ Der Download wird unmittelbar durch Anklicken des Links gestartet. Es wird kein kurzzeitiger Browser-Tab oder -Fenster geöffnet, die sich ohne sinnvollen Inhalt gleich wieder schließen, wie man das oft bei Web-Seiten sieht.
Als Variante kann der Browser bestimmte Mime-Types direkt anzeigen, wie z.B. GIF-, PNG-, JPG-Bilder, PDF-Dateien, je nach installierter Software noch mehr. Dies erreicht man durch hinzufügen von target="_blank" beim Link und entfernen der Code-Zeile für Content-Disposition:
{{{
<h:commandLink value="#{fileUpload.filename}" target="_blank" action="#{fileUpload.download}"
rendered="#{fileUpload.file != null}"/>
}}}
{{{
public void download() throws IOException {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
externalContext.setResponseContentType(mimeType);
externalContext.setResponseContentLength(file.length);
OutputStream outputStream = externalContext.getResponseOutputStream();
outputStream.write(file);
FacesContext.getCurrentInstance().responseComplete();
}
}}}
×