Best download file with struts 1.1 method

邮差的信 提交于 2019-12-11 13:39:33

问题


for a web application builded on struts and jsp technologies , i 'm looking for a good example wich explains how to download files from the server side


回答1:


i manage to do it with this few lines of code : just add this to your action :

OutputStream out = response.getOutputStream();
        response.setContentType("application/rtf");
        FileInputStream in = new FileInputStream("your_file_path");
        byte[] buffer = new byte[4096];
        int length;
        while ((length = in.read(buffer)) > 0){
            out.write(buffer, 0, length);
        }
        in.close();
        out.flush();


来源:https://stackoverflow.com/questions/12107909/best-download-file-with-struts-1-1-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!