gwt文件上传代码 [英] gwt file upload code

查看:138
本文介绍了gwt文件上传代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上传文件在我的应用程序,并希望设置文件应保存在我的本地系统上传后保存的路径。我使用下面的代码,但提交按钮得到没有响应,同时click.Please告诉我代码工作正常的gwt文件上传。
[code]

$ $ $ $ $ $ $ $ $ $ $ $ $ $ public void onModuleLoad() {
//创建一个FormPanel并将其指向一个服务。
final FormPanel form = new FormPanel();
form.setAction(/ myFormHandler);

//因为我们要添加一个FileUpload小部件,所以我们需要设置
//表单来使用POST方法和多部分MIME编码。
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);

//创建一个面板来保存所有的表单控件。
VerticalPanel面板=新的VerticalPanel();
form.setWidget(panel);

//创建一个文本框,给它一个名字以便提交。
final TextBox tb = new TextBox();
tb.setName(textBoxFormElement);
panel.add(tb);

//创建一个ListBox,给它一个名字和一些与
//它的选项相关联的值。
ListBox lb = new ListBox();
lb.setName(listBoxFormElement);
lb.addItem(foo,fooValue);
lb.addItem(bar,barValue);
lb.addItem(baz,bazValue);
panel.add(lb);

//创建一个FileUpload小部件。
FileUpload upload = new FileUpload();
upload.setName(uploadFormElement);
panel.add(上传);

//添加一个提交按钮。
panel.add(new Button(Submit,new ClickListener(){
public void onClick(Widget sender){
form.submit();
}
}));

//向表单添加事件处理程序。
form.addFormHandler(new FormHandler(){
public void onSubmit(FormSubmitEvent event){
//这个事件在提交表单前被触发,我们可以用
/ / b $ b $ if(tb.getText().length()== 0){
Window.alert(文本框不能为空);
event.setCancelled(true);
}
}

public void onSubmitComplete(FormSubmitCompleteEvent event){
//当表单提交成功完成时,
// fired。假设服务返回了text / html类型的响应,
//我们可以在这里获得结果文本(参见
的FormPanel文档//进一步解释)
Window.alert(event.getResults());
}
});

RootPanel.get()。add(form);




$ b $ p

Amandeep

解决方案

我终于用这个链接



真的是我在找什么。


I want to upload file in my application and want to set path where the files should be saved after uploading in my local system.I am using the following code but on the submit button getting no response while clicking.Please tell me the code which works fine for the file upload in gwt. [code]

public class FormPanelExample implements EntryPoint {

  public void onModuleLoad() {
    // Create a FormPanel and point it at a service.
    final FormPanel form = new FormPanel();
    form.setAction("/myFormHandler");

    // Because we're going to add a FileUpload widget, we'll need to set the
    // form to use the POST method, and multipart MIME encoding.
    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setMethod(FormPanel.METHOD_POST);

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

    // Create a TextBox, giving it a name so that it will be submitted.
    final TextBox tb = new TextBox();
    tb.setName("textBoxFormElement");
    panel.add(tb);

    // Create a ListBox, giving it a name and some values to be associated with
    // its options.
    ListBox lb = new ListBox();
    lb.setName("listBoxFormElement");
    lb.addItem("foo", "fooValue");
    lb.addItem("bar", "barValue");
    lb.addItem("baz", "bazValue");
    panel.add(lb);

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

    // Add a 'submit' button.
    panel.add(new Button("Submit", new ClickListener() {
      public void onClick(Widget sender) {
        form.submit();
      }
    }));

    // Add an event handler to the form.
    form.addFormHandler(new FormHandler() {
      public void onSubmit(FormSubmitEvent event) {
        // This event is fired just before the form is submitted. We can take
        // this opportunity to perform validation.
        if (tb.getText().length() == 0) {
          Window.alert("The text box must not be empty");
          event.setCancelled(true);
        }
      }

      public void onSubmitComplete(FormSubmitCompleteEvent event) {
        // When the form submission is successfully completed, this event is
        // fired. Assuming the service returned a response of type text/html,
        // we can get the result text here (see the FormPanel documentation for
        // further explanation).
        Window.alert(event.getResults());
      }
    });

    RootPanel.get().add(form);
  }
}

Thanks

Amandeep

解决方案

I have finally solved the problem using this Link

It is really what I was looking for.

这篇关于gwt文件上传代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆