此代码适用于 chrome。但在 Firefox 中,它不调用 servlet。下面是代码。不知道是不是浏览器的区别。
String URL= GWT.getModuleBaseURL()+"getType";
FormPanel formPanel = new FormPanel();
formPanel.setAction(URL);
formPanel.setEncoding(FormPanel.ENCODING_URLENCODED);
formPanel.setMethod(FormPanel.METHOD_GET);
formPanel.addSubmitHandler(new SubmitHandler(){
@Override
public void onSubmit(SubmitEvent event) {
// TODO Auto-generated method stub
System.out.println(event.getSource());
}
});
formPanel.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
public void onSubmitComplete(SubmitCompleteEvent event) {
System.out.println("in");
System.out.println(event.getResults());
}
});
formPanel.submit();
xml文件如下。
web.xml
<servlet>
<servlet-name>getType</servlet-name>
<servlet-class>msp2.server.getType</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>getType</servlet-name>
<url-pattern>/msp2_app/getType</url-pattern>
</servlet-mapping>`