How to download a file using GWT client?

做~自己de王妃 提交于 2019-12-22 04:16:23

问题


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:

  1. Make your GWT RPC method return the file content or the data to generate the file.
  2. On the client side, format a Data URI with the file content received or generate the data content.
  3. Use Window.open to 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!