struts上传

jsp页面
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<a href="xxxAction.do?fileId=...">点击下载</a>

struts.xml
<action name="xxxAction" class="downAction">
<result name="success" type="stream" >
<param name="fileName" >file</param>
<param name="contentDisposition" >attachment;filename=${filename}</param>
<param name="buffersize">1024</param>
</result>
downAction
private String filename;
private InputStream file;
private String fileId;
public String execute(){
ServletContext sc=ServletActionContext.getServletContext();
String path=sc.getRealPath("upload");
filename=""+fileId;
file=new FileInputStream(path+File.separator+filename);
return "success";

}


文件下载,在jsp页面加一段java代码,给你贴个例子:
jsp页面加上这段代码的话、就会弹出框框 提示你打开还是保存?
java.text.SimpleDateFormat tempDate = new java.text.SimpleDateFormat(
"yyyyMMddHHmmss");
String time = tempDate.format(new Date());
String fileName = "用户基本信息_" + time + ".doc";
fileName = new String(fileName.getBytes("GBK"), "ISO8859_1");
response.setHeader("Content-Disposition", "attachment;filename="
+ fileName);

response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值