【发布时间】:2018-10-11 09:56:55
【问题描述】:
我正在尝试实现 GWT 图片上传功能。我已经进行了所需的代码更改,但由于某种原因没有上传。在服务器端没有接收到图像。所以我在客户端(浏览器)检查了请求头和内容,然后我发现 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);
我在这里有什么遗漏吗?请提出建议。
谢谢。
【问题讨论】:
标签: file-upload gwt image-uploading image-upload