在jsp页面只写一个<a href="*!download.action">下载</a>
在action文件中写:
private String savepath="\\download\\exam";
public String getSavepath() {
return ServletActionContext.getServletContext().getRealPath(this.savepath);//得到物理路径
}
public String downloadQuestionTemplate(){
return "downloadQuestionTemplate";
}
public InputStream getInputStream() {
File file = new File(this.getSavepath()+File.separator+"文件名.xls");
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return fis;
}
在配置文件中action.xml写:
<result name="download" type="stream">
<param name="contentType">application/x-xls</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="QuestionTemplate.xls"</param>//下载页面的文件类型由此处的filename的文件类型决定
<param name="bufferSize">4096</param>
</result>
ok!
分享到:
相关推荐
使用struts2实现文件下载功能,可以直接运行!
在struts2基础上实现的包括单文件、多文件的上传及下载
struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置文件以及代码示例struts2配置...
Struts2下载文件时中文乱码和空格处理
使用struts2框架进行文件的上传并限制文件的大小与类型,使用struts2框架实现文件下载
struts2文件上传和下载 struts2文件上传和下载 struts2文件上传和下载 struts2文件上传和下载 struts2文件上传和下载
struts2中的文件上传和下载: 1.首先导入commons-fileupload-1.2.1.jar和commons-io-1.4.jar两个jar包 2.其次JSP页面中的文件上传控件所在的form必须设置属性enctype="multipart/form-data" 3.再次,struts2中...
网上的Struts2进行的文件下载一般都是单文件或者固定的文件,并没有(很少)实现随意文件的下载的例子 提供多文件上传,上传成功后,提供刚上传的文件下载功能(其他的都可以在其上面进行扩充) 多文件 上传 下载...
struts2文件下载极其简单struts2文件下载极其简单struts2文件下载极其简单struts2文件下载极其简单
struts2配置文件 struts2代码
Struts2上传文件(直接用request)
Struts2文件流方式导出下载excel、Txt、image图片,直接返回给浏览器提示下载,不生成临时文件,直接保存在客户端
struts2 库文件下载This product includes software developed by The Apache Software Foundation (http://www.apache.org/).
struts2下载文件
一个利用Struts2实现文件的上传下载,使用的是同步方式。没有用ajax请求
http://blog.csdn.net/johnjobs/article/details/8076832博文中附件的下载链接
Struts2中文件上传与下载案例
struts2所有jar包下载
博文链接:https://ychw668.iteye.com/blog/122843
Struts2 文件上传下载 多文件 单文件 实例;支持单个或多个文件的上传下载,并且自定义上传文件的大小和类型!!!