【问题标题】:GWT FormPanel method replaced by input parameterGWT FormPanel 方法被输入参数替换
【发布时间】:2012-09-19 08:01:24
【问题描述】:

我们在我正在维护的 GWT 应用程序中发现了一个奇怪的新错误,我不确定它何时成为问题。可能使用新的 Firefox 版本。

我们使用 FormPanel 向服务器发送 POST 请求,基本上就像我在网上看到的许多示例一样。但是由于我们实际上想要一个 PUT 请求,所以其中一个隐藏的输入参数被命名为“method”,其值为“put”。

现在,当我在 Fiddler 中查看来自 Firefox 的请求时,它正在被转换为带有 QueryString 中所有参数的 GET 请求。在 IE 和 Chrome 中,参数位于 POST 请求的正文中。

我在警报中显示了 FormPanel.getMethod() 的值,在 IE 和 Chrome 中显示字符串“post”,而在 firefox 中显示“object HTMLInputElement”。不幸的是,托管模式调试不适用于此项目。

很明显,FormPanel 的 getMethod() 函数返回的是名为 method 的隐藏输入参数,而不是 Firefox 中实际表单的方法。

从技术上讲,我应该避免更改 servlet,因为它来自我们使用的开源项目,但我发现我可以通过将隐藏输入参数的名称两端更改为“_method”来解决此问题。

有人见过这样的吗?我在 Google 中找不到任何内容。

更新:我们使用 GWT 2.3 以防万一

【问题讨论】:

  • 关于这个问题的进展有什么更新吗?..

标签: firefox gwt post


【解决方案1】:

可以在这里找到一些见解Are the PUT, DELETE, HEAD, etc methods available in most web browsers? 我还建议使用 XMLHttpRequest。在这种情况下,您 [很可能] 不必在服务器端进行任何更改。

如果你使用提交按钮,你可以在它的clickHandler函数中写:

submitMyForm(yourTextBox.getText(), self); 
// self - is the instance of main class (named UploadForm here), needs to be passed here for future reference

还有更多(您可以根据自己的需要进行调整):

private native void submitMyForm(String text, UploadForm handler)/*-{
   var fd = new FormData();
   fd.append("textValue", text);

   var xhr = new XMLHttpRequest();
   var upload = xhr.upload;

   readyStateChangeHandler = function () {
      if (xhr.readyState == 4) {
         if (xhr.status == 200) {
           var serverResponse = eval(xhr.responseText); // optional               
           handler.@com.project.UploadForm::onUploadIsDone(Lcom/google/gwt/core/client/JavaScriptObject;)(serverResponse);
         } else {
           handler.@com.project.UploadForm::onUploadFailed(I)(status);
         }
      }
   };

   xhr.onreadystatechange = readyStateChangeHandler;
   xhr.open("PUT", yourActionUrlHere);
   xhr.send(formData);
}-*/;

【讨论】:

  • 如果使用,onUploadIsDone() 和 onUploadFailed() 必须在 UploadForm 类中实现。
猜你喜欢
  • 1970-01-01
  • 2012-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-20
  • 2011-02-09
  • 1970-01-01
相关资源
最近更新 更多