【问题标题】:GWT RequestBuilder problemGWT RequestBuilder 问题
【发布时间】:2011-01-26 15:30:08
【问题描述】:

我正在尝试在我们的 gwt 应用程序中插入一个 jsp。我正在为此使用请求生成器。这是我的代码:

String url = "http://localhost:8080/my-spring-example/hello.htm";
RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
RequestCallback callback = new RequestCallback() {
 public void onError(Request request, Throwable exception) {
  spring.setHTML("Die Daten konnten nicht geladen werden");
 }

 public void onResponseReceived(Request request, Response response) {
  String responseAsText = response.getText();
  if (responseAsText.equals("") || responseAsText == null ){
   spring.setHTML("Der String ist leer");   
  } else {
   spring.setHTML(responseAsText);
  }
 }
};

try {
 rb.sendRequest(null, callback);
} catch (RequestException e) {
 e.printStackTrace();
}

如果我打电话给http://localhost:8080/my-spring-example/hello.htm,萤火虫的反应是:

<head><title>Hello :: Spring 3 Application</title></head>
<body>
 <h1>Hello World, Spring 3.0!</h1>
 <p>Es gibt 32 Einträge</p>
</body>

如果我通过我们的 gwt 应用程序调用,firebug 中的响应是空字符串。

如果我打电话给http://localhost:8080/my-spring-example/hello.htm,wireshark 的响应是:

<head><title>Hello :: Spring 3 Application</title></head>\n
<body>\n
\t<h1>Hello World, Spring 3.0!</h1>\n
\t<p>Es gibt 32 Eintr\344ge</p>\n
</body>

如果我通过我们的 gwt 应用程序进行调用,wireshark 中的响应是相同的:

<head><title>Hello :: Spring 3 Application</title></head>\n
<body>\n
\t<h1>Hello World, Spring 3.0!</h1>\n
\t<p>Es gibt 32 Eintr\344ge</p>\n
</body>

我不明白,出了什么问题....调用正确,响应来了,但是发生了一些事情,所以 gwt 客户端只显示空字符串作为响应。我很困惑....

【问题讨论】:

    标签: jsp gwt insert request response


    【解决方案1】:

    我已经解决了问题...对于 jsp 调用,我使用的是 localhost,但我正在通过另一台主机调用 webapp。我必须遵循 JavaScript 的“同源策略”,现在一切正常。

    编辑:如果您使用相同的主机和协议进行调用,则 jsp 只能插入。例如 - 我通过http://www.mycompany.com:8080/gwt-client/ 调用我们的应用程序。对于 jsp,调用 http://localhost:8080/my-spring-example/hello.htm。 jsp 和 web 应用程序位于不同的主机上。如果我将 jsp 调用更改为 http://www.mycompany.com:8080/my-spring-example/hello.htm,则可以。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-30
      • 1970-01-01
      • 1970-01-01
      • 2011-06-16
      • 1970-01-01
      • 1970-01-01
      • 2013-04-21
      • 2013-01-05
      相关资源
      最近更新 更多