You can use something this code, I think it's self explaining.

// Create a FormPanel and point it at a service.
    final FormPanel form = new FormPanel();
    form.setAction(GWT.getHostPageBaseURL() + YOUR_SERVLET_PATH_HERE);

    // To upload a file with the form we need to set to multipart MIME 
encoding and POST method.
    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setMethod(FormPanel.METHOD_POST);

    // Create a panel to hold all of the form widgets.
    panel = new VerticalPanel();
    form.setWidget(panel);

    // Create a FileUpload widget.
    final FileUpload upload = new FileUpload();
    upload.setName("file");
    panel.add(upload);

    [SOME OTHER CODE HERE IF YOU WANT]

    // Add a submit button.
    final Button btnSubmit = new Button("Upload package");
    btnSubmit.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
        if (upload.getFilename().length() == 0)
            Window.alert("The file path must not be empty");
        else {
            form.submit();
          }
        }
    });
    panel.add(btnSubmit);

Le mardi 14 février 2012 03:59:31 UTC-5, kimi a écrit :
>
> hi there
> what's the best approach to handle a simple fileupload in gwt ? 
> normally it would be a normal POST with File-Field, problem is that a post 
> to a servlet will make the page "refresh", that means user will be redirect 
> from current page. is there a lightweight-approach which doesnt require 
> this ? possibly an iframe which contains the form ?
>
> thanx 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/RBsP8boJIIAJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to