文件下载—SSH框架文件下载

1、准备下载的api组件

<dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
</dependency> 
<dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.3.1</version>
    </dependency>

 

2、编写前台表单下载入口

使用struts2的表单标签编写...

3、编写action类

 

[省略了set,get方法的,action里面必须填set,get否则不能注入]

inputPath:表示下载文件的目录,指定去哪个目录下载。

fileName:指定下载的文件名

这两个参数一般从前台传过来

 

4、配置拦截器

1:stream结果类型:将文件数据(通过inputStream获取)直接写入响应流

2:相关的下载参数配置:

3:ContentType常见的几种文件下载类型:(这里我们要用任意二进制)

原文地址:https://www.cnblogs.com/domi22/p/8059744.html