How to download a file via a button click i GWT?

后端 未结 4 1046
北恋
北恋 2021-01-05 13:34

I hava a servleta that serves files?

I\'m building a page with a \"Download\" button usung a GWT.

How to make a GWT client download a file in an onClick even

4条回答
  •  太阳男子
    2021-01-05 14:09

    None of the solutions above worked for me, then I realized I already have an implementation working. Here's how I do it:

    Window.open(fileUrl, "_parent", "");
    

    But the key is in your servlet:

    response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
    

    This solution will NOT open new window and instead directly opens the "Save As" dialog. Best of both worlds imo.

提交回复
热议问题