can GWT provide the download of a csv file

107 views
Skip to first unread message

123

unread,
Jun 29, 2007, 2:44:03 AM6/29/07
to Google Web Toolkit
in the client .i have a button .what i want is when i click this
button .thougth one sql i can download the csv file in the server ?
any one help me ?

123

unread,
Jun 29, 2007, 2:45:28 AM6/29/07
to Google Web Toolkit

Ryan Dewsbury

unread,
Jun 29, 2007, 10:00:00 AM6/29/07
to Google Web Toolkit
Do you want to download the csv from the server or to the server?

Either way you'll need to use the HTTP module and add this line to
your module XML file:

<inherits name="com.google.gwt.http.HTTP"/>

Then you need to use the HTTPRequestBuilider class. If you are sending
data to the server create it like this:

HTTPRequestBuilder builder = new
HTTPRequestBuilder(RequestBuilder.POST, "/your_server_script");
builder.setHeader("Content-type", "application/csv");
try{
builder.sendRequest( your_csv_as_a_string, new RequestCallback(){
public void onError(Request request, Throwable exception)
{ GWT.log( "error", exception ); }
public void onResponseReceived(Request request, Response response){
// success
}
});
}
catch (RequestException e){ GWT.log( "error", e); }

Notice that the POST method is used. You'll need to have a script of
servlet on the server capable on handling this post.

If you want to download a csv from the server you need to use the GET
method and handle the RequestCallback to read the results:

final String csvString = null;
HTTPRequestBuilder builder = new
HTTPRequestBuilder(RequestBuilder.GET, "/your_csv.csv");
try{
builder.sendRequest( null, new RequestCallback(){
public void onError(Request request, Throwable exception)
{ GWT.log( "error", exception ); }
public void onResponseReceived(Request request, Response response){
csvString = response.getText();
}
});
}
catch (RequestException e){ GWT.log( "error", e); }


Hope this helps!

Reply all
Reply to author
Forward
0 new messages