博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
下载的时候如果文件名是中文就变成zip.zip
阅读量:4613 次
发布时间:2019-06-09

本文共 1619 字,大约阅读时间需要 5 分钟。

struts2

 

/WEB-INF/web.xml

blk
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
index.html

 

/WEB-INF/classes/struts.xml

/exceptionHandle/exception.jsp
/exceptionHandle/exception.jsp
\down\images\文件.zip
application/zip
targetFile
filename="文件.zip"
4096

 

/down/strutsDown.html

    Struts2的文件下载    

Struts2的文件下载

下载Struts2的Logo:下载文件

 

down.FileDownloadAction

 

package down;import java.io.InputStream;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.Action;public class FileDownloadAction implements Action {    private String inputPath;    public void setInputPath(String value)    {        inputPath = value;    }    /*     下载用的Action应该返回一个InputStream实例,     该方法对应在result里的inputName属性值为targetFile    */    public InputStream getTargetFile() throws Exception     {        return ServletActionContext.getServletContext().getResourceAsStream(inputPath);    }    public String execute() throws Exception    {        return SUCCESS;    }}

 

 

 

转载于:https://www.cnblogs.com/qrlozte/p/3782378.html

你可能感兴趣的文章
acwing 651. 逛画展
查看>>
Vijos P1243 生产产品 (单调队列优化DP)
查看>>
iOS常用第三方库 -转
查看>>
Android布局学习
查看>>
jQuery中事件绑定与解绑
查看>>
js原生Ajax的封装与使用
查看>>
一种公众号回复关键词机制
查看>>
基于 Web 的 Go 语言 IDE - Wide 1.1.0 公布!
查看>>
nyist oj 138 找球号(二)(hash 表+位运算)
查看>>
ytu 1910:字符统计(水题)
查看>>
201671030110 姜佳宇 实验三作业互评与改进
查看>>
python的沙盒环境--virtualenv
查看>>
软件自动化测试——入门、进阶与实战
查看>>
BZOJ1878 [SDOI2009]HH的项链 树状数组 或 莫队
查看>>
BZOJ3675 [Apio2014]序列分割 动态规划 斜率优化
查看>>
2016.10.24 继续学习
查看>>
产品功能对标 - 服务授权管理
查看>>
各地IT薪资待遇讨论
查看>>
splay入门
查看>>
带CookieContainer进行post
查看>>