2011-01-24 64 views
1

我試圖在我們的gwt應用程序中聲明一個jsp。我正在使用請求生成器。在這裏我的代碼:GWT RequestBuilder問題

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應用程序,在螢火蟲的反應是空字符串。

如果是Ⅱ呼叫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

我已經解決了問題...爲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,則可以使用。