I have the following problem.
I created a class to take care of all calls to a database. I'm using RequestBuilder on the front end of GWT to send a HTTP GET r开发者_如何学Pythonequest.
public String getDadosGET(String phpFilePath) {
rb = new RequestBuilder(RequestBuilder.GET, phpFilePath);
rb.setHeader(header, headerValue);
try {
response = rb.sendRequest(null, new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
text = response.getText();
}
@Override
public void onError(Request request, Throwable exception) {
}
});
} catch (RequestException e) {
e.printStackTrace();
}
return text;
}
Now If I output the text inside the onResponseReceived
method, It's not null.
If done right before return text
, it's null.
What I need is to force the program to get the data first, then return the method.
Thanks.
I think you haven't quite understood the concept of asynchronous calls. Check out the this article.
I don't think there's a way of making a GWT call synchronously, which is what you seem to want.
精彩评论