it seem to be a pain when trying to perform cross-site requests,
实际上,如果我们可以在 Servlet 响应标头中设置,您可以从 GWT RequestBuilder 发出跨站点请求
Response.setHeader("Access-Control-Allow-Origin"," http://yourrestserviceur.com/url ");
should I create a http client like the apache client on server-side code, and implement
a set of services that use it to make request to the backend?
不,这不是必需的。利用RequestBuilder
RequestBuilder 示例:
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
try {
Request request = builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
displayError("Couldn't retrieve JSON");
}
public void onResponseReceived(Request request, Response response) {
if (200 == response.getStatusCode()) {
updateTable(asArrayOfStockData(response.getText()));
} else {
displayError("Couldn't retrieve JSON (" + response.getStatusText()
+ ")");
}
}
});
} catch (RequestException e) {
displayError("Couldn't retrieve JSON");
}