FormPanel's javadoc的例子说:
“...假设服务返回了text / html类型的响应,我们可以在此处获取结果文本(请参阅FormPanel文档以获得进一步说明)......”
然而,javadoc并未解释有关此主题的内容。有人在表单提交后找到了如何从服务器发回HTML响应吗?
答案 0 :(得分:7)
将FormHandler添加到FormPanel,在onSubmitComplete中,您将收到FormSubmitCompleteEvent。调用其getResults()方法以获取结果。
form.addFormHandler(new FormHandler() {
public void onSubmit(FormSubmitEvent event) { // validation etc }
public void onSubmitComplete(FormSubmitCompleteEvent event} {
Window.alert(event.getResults()); // display the result
}
};
答案 1 :(得分:4)
此问题仅在调试模式下发生。看看这个:http://code.google.com/p/google-web-toolkit/issues/detail?id=3832
答案 2 :(得分:3)
继“Robert Munteanu”的装扮之后你应该看看:
你可以看到:
getResults
public java.lang.String getResults()
获取表单提交的结果文本。
返回:
结果html,如果读取错误则为null
提示:
由于将表单提交到其他域,结果html可能为null。
答案 3 :(得分:0)
// ===========在客户端:
SubmitCompleteHandler sch = new SubmitCompleteHandler()
{
public void onSubmitComplete(SubmitCompleteEvent event)
{
//get back the data results that had input the .xml
String dpsString = event.getResults();
//And do your wanted action with the result
System.out.println(dpsString);
}
};
uploadForm.addSubmitCompleteHandler(sch);
// ===========在服务器端:
// parse and handle file, e.g. if there is an xml file
...
InputStream fileImputStream = uploadItem.getInputStream();
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(fileInputStream);
doc.getDocumentElement().normalize();
System.out.println("Root element of the doc is " + doc.getDocumentElement().getNodeName());
...
//Response to the request with the result
dpsString = doc.getDocumentElement().getNodeName();
response.getWriter().write(new String(dpsString));
答案 4 :(得分:0)
我尝试用机器名替换本地主机它没有帮助[有人说它帮助了他们],但这是一个跨域java脚本问题,所以我尝试使用web xml和我分配的URL模式得到了一个String结果。有关详细信息,请查看此链接中的橡皮鸭回答
答案 5 :(得分:0)
我能够使用以下代码在DEV模式下获得结果消息:
客户方:
FormPanel formPanel = new FormPanel();
FormElement.as(formPanel.getElement()).setAcceptCharset("UTF-8");
formPanel.setAction(sb.toString());
formPanel.setMethod(FormPanel.METHOD_POST);
formPanel.setVisible(false);
RootPanel.get().add(formPanel);
formPanel.submit();
formPanel.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
@Override
public void onSubmitComplete(SubmitCompleteEvent event) {
String results = event.getResults();
}
});
服务器端:
response.setContentType("text/html");
response.setHeader("Pragma", "No-cache");
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write(e.getMessage());
浏览器:Firefox 24.3.0,GWT版本:2.5.1
答案 6 :(得分:0)
对我来说问题是我使用FormPanel
构造函数构建了FormPanel(String)
。使用默认构造函数,我的SubmitCompleteHandler
刚刚起作用。