读书人

使用struts2-codebehind插件上载附件注

发布时间: 2012-09-28 00:03:35 作者: rapoo

使用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的值也要与之一致。

读书人网 >开源软件

热点推荐