Download generated HTML file
I have a generated HTML file which I need to be able to download at the click of a button (so not opening in a new window, just showing the save file dialog for this particular html file).
The code I have so far:
AVaadinApplication application = VaadinContext.getCurrentInstance().getVariable(VaadinContext.APPLICATION, AVaadinApplication.class);
StreamResource inputHTML = new StreamRes开发者_如何学运维ource(
new StreamResource.StreamSource() {
private static final long serialVersionUID = 1L;
@Override
public InputStream getStream() {
return new ByteArrayInputStream(getHelpContentString(getLocale()).getBytes());
}
}, "help_" + getLocale() + ".html", application);
inputHTML.setCacheTime(0);
Any help is greatly appreciated as I've been breaking my head on this.
Wrap the HTML in a Zip file. No browser I know will attempt to display a Zip file, but instead push it out as a file to 'Open (in a Zip archive program) or Save'.
You should set the HTTP Content-Disposition
header of the result to attachment. How you do that depends on how you interact with the web server. Are yore code running as a servlet, in the play framwork, as a cgi, etc?
精彩评论