Create a dynamic file and upload it to GWT

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

+3
source share
5 answers

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).

+1

. , .

. :

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();
        }
    }
}
+3
    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), .

+1

Aki Miyazakis HTML5 GWT. .

AFAIK, Chrome, , .

0

URI :

, URI :

csv jQuery

0

All Articles