GWT RequestBuilder问题

时间:2011-01-24 10:58:36

标签: jsp gwt insert request response

我正试图在我们的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客户端只显示空字符串作为响应。我很困惑......

1 个答案:

答案 0 :(得分:1)

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

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