I am developing a GWT application. This application runs on the server. Well, I implement a button that calls a method that creates a local file on the server side. However, I would like to download / generate this file on the client side. How can I do this in GWT?
thank
The current situation is that not all browsers can work with the local file system, so there is no universal solution in GWT. Also, as far as I know, the FilesSstem API is not complete.
, , Flash- ( Flash API GWT).
. , .
. :
public class DownloadServlet extends HttpServlet { private FileManager fileManager; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String encodedFileName = req.getRequestURI().substring( req.getContextPath().length() + req.getServletPath().length() + 1); String decodedFileName = URLDecoder.decode(encodedFileName, "utf-8"); File downloadableFile = fileManager.toFile(decodedFileName); ServletOutputStream os = resp.getOutputStream(); try { InputStream is = FileUtils.openInputStream(downloadableFile); try { IOUtils.copy(is, os); } finally { is.close(); } } finally { os.close(); } } }
private native void Download(String filename, String text)/*-{ var pom = document.createElement('a'); pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); pom.setAttribute('download', filename); document.body.appendChild(pom); pom.click(); document.body.removeChild(pom); }-*/;
JSNI GWT, , , JSON (String), .
Aki Miyazakis HTML5 GWT. .
AFAIK, Chrome, , .
URI :
Window.open
, URI :
csv jQuery