tags:

views:

26

answers:

1

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.

+1  A: 

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", "_blank", "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

Kerem
ok - the new window closes immediately after opening (Chrome browser)
lbownik
ok Window.open("http://127.0.0.1:8888/file.rar", "_blank", null); - works
lbownik