使用struts2-codebehind插件下载附件注解示例

使用struts2-codebehind-plugin-2.1.2.jar插件下载Excel附件注解示例


import org.apache.struts2.config.Result;
import org.apache.struts2.config.Results;
import org.apache.struts2.dispatcher.StreamResult;


@Results({ @Result(name = FileDownloadAction.RESULT_EXCEL, value = "stream", type = StreamResult.class, params = { "contentType",
"application/vnd.ms-excel", "inputName", "stream",
"contentDisposition", "attachment;filename=\"file2.xls\"",
"bufferSize", "1024" }) })
public class FileDownloadAction {

public static final String RESULT_EXCEL = "excel";
private InputStream stream;

public String execute() throws Exception {
stream = new FileInputStream("c:\\temp\\file.xls");
return RESULT_EXCEL;

}


//... getter and setter
}

这里最重要的是Result里面params的写法,params后面的大括号中,奇数个字符串是key值,偶数个字符串是value值。
[color=red]其中,inputName的值-stream要和Class中的InputStream的属性名一致,而Result中的value的值也要与之一致。[/color]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值