| From | Sent On | Attachments |
|---|---|---|
| 123 | Jun 28, 2007 11:43 pm | |
| 123 | Jun 28, 2007 11:45 pm | |
| Ryan Dewsbury | Jun 29, 2007 6:59 am |
| Subject: | Re: can GWT provide the download of a csv file | |
|---|---|---|
| From: | Ryan Dewsbury (r....@rdews.com) | |
| Date: | Jun 29, 2007 6:59:37 am | |
| List: | com.googlegroups.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!
On Jun 29, 2:45 am, 123 <liu...@hotmail.com> wrote:
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 ?





