GWT Servlet不会从集成在Web应用程序中的GWT Form Panel调用

时间:2015-05-27 05:20:56

标签: java servlets gwt

我有一个GWT应用程序,其中有一个带有文件上传的表单面板。然后有一个servlet来处理上传的文件。整个应用程序集成在一个struts Web应用程序中。

以下是代码段:

final FormPanel form = new FormPanel();
form.setAction(GWT.getModuleBaseURL()+"upload");
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
VerticalPanel formPanel = new VerticalPanel();
form.setWidget(formPanel);

Label lblSelectFile = new Label();
lblSelectFile.setText("Select cient_secret.json file: ");
formPanel.add(lblSelectFile);

FileUpload fileUpload = new FileUpload();
fileUpload.setName("fileUpload");
formPanel.add(fileUpload);

Button upload = new Button("Upload");
upload.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            form.submit();
        }
    });

formPanel.add(upload);

form.addSubmitHandler(new FormPanel.SubmitHandler() {
    public void onSubmit(SubmitEvent event) {
          if (fileUpload.getName().length() == 0) {
                    Window.alert("The file must not be empty");
                        event.cancel();
          }
      }
    });

form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
 public void onSubmitComplete(SubmitCompleteEvent event) {
           Window.alert(event.getResults());
 }

});

的web.xml

<servlet>
  <servlet-name>uploadServlet</servlet-name>
  <servlet-class>
      com.test.FileUploadServlet
  </servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>uploadServlet</servlet-name>
 <url-pattern>*/upload</url-pattern>
</servlet-mapping>

现在的问题是这个servlet没有从表单面板调用,我得到了HTTP状态404.

我做错了什么????

1 个答案:

答案 0 :(得分:0)

AFAICT,*/upload不是有效的servlet-mapping url-pattern。 *只能是&#34;扩展程序的前缀&#34; (如*.jsp)。您必须使用moduleName/uploadupload,然后更改getModuleBaseURL getHostPageBaseURL