Java servlet未在SubmitComplete上启动(Google应用程序引擎)
GWT 2.5.1/ 应用程序引擎SDK 1.8.9 我试图将一个.CVS文件上传到一个servlet,以便使用FormPanel进行解析,但是我没有从servlet得到任何响应 客户端代码 我从onSubmit()中看到窗口,但onSubmitComplete没有响应 web.xml relvant web.xml代码Java servlet未在SubmitComplete上启动(Google应用程序引擎),java,google-app-engine,servlets,gwt,Java,Google App Engine,Servlets,Gwt,GWT 2.5.1/ 应用程序引擎SDK 1.8.9 我试图将一个.CVS文件上传到一个servlet,以便使用FormPanel进行解析,但是我没有从servlet得到任何响应 客户端代码 我从onSubmit()中看到窗口,但onSubmitComplete没有响应 web.xml relvant web.xml代码 上传的CSVParser ca.ubc.cs310.gwt.healthybc.server.UploadedCSVParser 上传的CSVParser /healthyb
上传的CSVParser
ca.ubc.cs310.gwt.healthybc.server.UploadedCSVParser
上传的CSVParser
/healthybc/uploadServlet
服务器代码
公共类UploadedCSVParser扩展HttpServlet{
@凌驾
受保护的void doGet(HttpServletRequest请求,HttpServletResponse响应)抛出ServletException,IOException
{
doPost(请求、响应);
}
@凌驾
受保护的void doPost(HttpServletRequest请求、HttpServletResponse响应)引发ServletException、IOException
{
response.setContentType(“text/html”);
PrintWriter out=response.getWriter();
out.println(“”);
out.println(“”);
out.println(“servlet标题”);
out.println(“”);
out.println(“”);
out.println(“”);
out.println(“文本在此显示”);
out.println(“”);
out.close();
}
现在服务器代码就在那里,看我是否真的得到了响应。
在我的浏览器中直接输入URL…/healthybc/uploadServlet(我使用的是firefox)会给我预期的“文本在此显示”输出,但我没有收到任何迹象表明提交表单时onSubmitComplete曾经运行过。我开始认为信息永远不会到达servlet
我做错什么了吗?有没有什么简单的方法可以检查servlet是否真的被调用了?我不知怎么地修复了它。我从一个已知的工作模板中重新定义了客户端,我认为它的顺序可能与我最初使用的略有不同
final FormPanel form = new FormPanel();
form.setMethod(FormPanel.METHOD_POST);
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setAction("/healthybc/uploadServlet");
// then there's a button they can click which calls form.submit();
form.setWidget(new Button("Submit", (new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
form.submit();
}
})));
buttonPanel.add(form);
final FileUpload fileUpload = new FileUpload();
fileUpload.setName("Browse");
buttonPanel.add(clinicFileUpload);
// Add an event handler to the form.
form.addSubmitHandler(new FormPanel.SubmitHandler() {
public void onSubmit(SubmitEvent event) {
// This event is fired just before the form is submitted. We can take
// this opportunity to perform validation.
if (fileUpload.getFilename().length() == 0) {
Window.alert("The text box must not be empty");
event.cancel();
}
else if (!fileUpload.getFilename().endsWith(".csv")){
Window.alert("Can only upload .csv files");
event.cancel();
}
}
});
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 (see the FormPanel documentation for
// further explanation).
Window.alert(event.getResults());
}
});
public class UploadedCSVParser extends HttpServlet{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doPost(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title> servlet title</title>");
out.println("</head>");
out.println("<body>");
out.println("</body>");
out.println("TEXT GOES HERE");
out.println("</html>");
out.close();
}
final FormPanel form = new FormPanel();
form.setMethod(FormPanel.METHOD_POST);
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setAction("/healthybc/uploadServlet");
// then there's a button they can click which calls form.submit();
form.setWidget(new Button("Submit", (new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
form.submit();
}
})));
buttonPanel.add(form);
final FileUpload fileUpload = new FileUpload();
fileUpload.setName("Browse");
buttonPanel.add(clinicFileUpload);
// Add an event handler to the form.
form.addSubmitHandler(new FormPanel.SubmitHandler() {
public void onSubmit(SubmitEvent event) {
// This event is fired just before the form is submitted. We can take
// this opportunity to perform validation.
if (fileUpload.getFilename().length() == 0) {
Window.alert("The text box must not be empty");
event.cancel();
}
else if (!fileUpload.getFilename().endsWith(".csv")){
Window.alert("Can only upload .csv files");
event.cancel();
}
}
});
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 (see the FormPanel documentation for
// further explanation).
Window.alert(event.getResults());
}
});