问题
What is the best way to download a pdf file using GWT client ? Should I invoke a normal servlet to do that ? or is there a different preferred approach to handle this problem ?
I am new to GWT, so if some sample code would be of great help.
Thanks Deep
回答1:
Try it with GET...
Window.open(GWT.getHostPageBaseURL() + "FileRepository/doDownload?docId=" + dokument.getId(), "", "");
回答2:
You can implement a Servlet download the file OR you can do that using Data URIs:
- Make your GWT RPC method return the file content or the data to generate the file.
- On the client side, format a Data URI with the file content received or generate the data content.
- Use
Window.opento open a file save dialog passing the formatted DataURI.
Take a look at this reference, to understand the Data URI usage:
Export to csv in jQuery
回答3:
the best way is to navigate your browser to that file
on download button add click handler:
Button downloadButton = new Button("Download");
downloadButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.open("url_of_file", "download File", "");
}
});
来源:https://stackoverflow.com/questions/4020949/how-to-download-a-file-using-gwt-client