简体   繁体   中英

How do I use a GWT RPC to save a file on the client side?

I'm looking for specific code on how to send a file from the server-side of a GWT application so that the client-side user can save it on his machine. Currently, the app allows the user to upload a file, reads it, and puts certain values from the file into editable text boxes. When the user hits the "save as" button, it collects that edited data, puts it back into the file string, and sends that string to the server, where I want it to be put into a file and pushed back to the user on the client side, so that they can save it to their machine. How exactly do I accomplish that?

Sorry if this seems like an obvious thing, but I'm relatively new to GWT and java in general. Thanks!

I think that you want the way for download a file using content-type from server using GWT.

The easiest way that I have found is create a iFrame :

import com.google.gwt.user.client.ui.NamedFramerdddccvc   

...
NamedFrame iframe = new NamedFrame(frameName);        
iframe.setVisible(false);

parent.addChild(iframe);
iframe.setUrl(url);

It's important that the url from the server return a page with content type "text/plain" or using the valid requested.

What you can do is create a servlet, that generates the text as content and set the matching mimetype for the content. In you app you can call this servlet via the by Fernando suggested IFrame method.

There are many suggestions here on Stackoverflow on how to do it. Search for [java] file download serlvet and you will find lots of examples/guidelines on how to do this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM