Pages

Thursday, May 26, 2011

GWT: How read a remote file with GWT ?

 How read a remote file with GWT ?

If we want to read a remote file using GWT,
the following code will do this.

Add the following import statements.

import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.Response;
import com.google.gwt.user.client.ui.Frame;

try{
 RequestBuilder requestBuilder = 
 new RequestBuilder( RequestBuilder.GET, "url.cfg" );
 requestBuilder.sendRequest( null, new RequestCallback(){
public void onError(Request request, Throwable exception) {
                     //ERROR
 }
public void onResponseReceived(Request request, Response response) {
            String url="";
            url=response.getText();
            Frame frame = new Frame(url);
            frame.setWidth("900px");
            frame.setHeight("600px");
            parent.add(frame);
               }} );
         }
    catch(Exception E){
//ERROR
    }

Reference: http://stackoverflow.com/questions/2529953/how-read-a-remote-file-with-gwt

No comments:

Post a Comment