使用Struts 1.1方法的最佳下载文件 [英] Best download file with struts 1.1 method

查看:64
本文介绍了使用Struts 1.1方法的最佳下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于基于struts和jsp技术的Web应用程序,我正在寻找一个很好的例子,
wich解释了如何从服务器端下载文件

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

推荐答案

我可以用以下几行代码来做到这一点:$ b​​ $ b只需将其添加到您的操作中即可:

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();

这篇关于使用Struts 1.1方法的最佳下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆