GWT 图片上传空内容

GWT Image Upload empty content

我正在尝试实现 GWT 图片上传功能。我已经进行了所需的代码更改,但由于某种原因没有进行上传。在服务器端未接收到图像。所以我在客户端(浏览器)检查了请求 header 和内容,然后我发现 Content-Length: 44(只是 44)。然后我意识到图像在提交时没有被发送到服务器。请检查以下 GWT 代码。

    VerticalPanel vp = new VerticalPanel();
    vp.add(CommonFormLayoutUtil.createLabel("Upload"));
    final FormPanel form = new FormPanel();
    form.setAction("CGIImageUpload");
    // set form to use the POST method, and multipart MIME encoding.
    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setMethod(FormPanel.METHOD_POST);

    final FileUpload fileUpload = new FileUpload();
    Button uploadButton = new Button("Upload");
    uploadButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            //get the filename to be uploaded
            String filename = fileUpload.getFilename();
            if (filename.length() == 0) {
                showError("No File Specified!", null);
            } else {
                //submit the form
                form.submit();                    
            }               
        }
    });
    vp.add(fileUpload);
    vp.add(uploadButton);

    form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {

        @Override
        public void onSubmitComplete(SubmitCompleteEvent 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 
            showError(event.getResults(), null);        
        }
    });
    form.add(vp);

我在这里遗漏了什么吗?请提出建议。

谢谢。

FormPanel 声明如下:

"This panel can be used to achieve interoperability with servers that accept traditional HTML form encoding. The following widgets (those that implement com.google.gwt.user.client.ui.HasName) will be submitted to the server if they are contained within this panel"(强调我的)

您需要设置FileUpload小部件的名称,否则它不会被FormPanel提交。

fileUpload.setName("someName");

尝试设置它,它应该可以工作