首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

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

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

使用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值。
其中,inputName的值-stream要和Class中的InputStream的属性名一致,而Result中的value的值也要与之一致。

热点排行