客户端代码:
@UiHandler("form")
void onFormSubmission(SubmitCompleteEvent event) {
hideProcessingPopUp();
if (event.getResults().contains("Exception")) {
// handle exception
}
}
doPost方法中的Servlet代码:
response.setContentType("text/csv");
response.setHeader("Content-Disposition", "attachment;filename="
+ exportType + ".csv");
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
response.getOutputStream(), "UTF-8"));
// Adding content
List<CustomObject> list = (List<CustomObject>) anonymousList;
for (CustomObject eachObject : list) {
writer.append(eachObject.getContent());
writer.newLine();
}
writer.flush();
// Gently close streams/writers.
close(writer);
return fileContent;
Servlet代码很好,就像我得到预期的数据和文件一样。问题是响应未到达客户端,即SubmitCompleteEvent。请帮我一下,提前谢谢。
浏览器就是这样工作的;FormPanel
的javadoc实际上警告您:
后端服务器应以"text/html"的内容类型进行响应,这意味着返回的文本将被视为html。如果服务器指定了任何其他内容类型,那么onFormSubmit事件中发送的结果HTML在浏览器之间将是不可预测的,并且
onSubmitComplete
事件可能根本不会触发。