Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

gwt

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 event?

P.S. Anchor works, but Button looks better.

like image 907
Łukasz Bownik Avatar asked Sep 10 '10 12:09

Łukasz Bownik


2 Answers

if you have the file address. You can open a window like below:

downloadButton.addClickHandler(new ClickHandler() {

    @Override
    public void onClick(ClickEvent event) {
        Window.open("http://127.0.0.1:8888/file.rar", "_self", "enabled");
    }
});

and that javadoc can help you http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/user/client/Window.html#open%28java.lang.String,%20java.lang.String,%20java.lang.String%29

like image 173
Kerem Avatar answered Sep 24 '22 02:09

Kerem


I like

Window.Location.replace("/downloadServlet");
like image 29
Chloe Avatar answered Sep 21 '22 02:09

Chloe