struts2文件下载示例
来源:互联网 发布:plsql中导入excel数据 编辑:程序博客网 时间:2024/05/16 05:42
首先先是不基于struts2的下载示例
在动作类action中的download(),代码如下:public String download(){ try { FileInputStream fis = new FileInputStream(new File(path,newUser.getFilename()));//其中path为文件所在路径 newUser.setInputStreamxxx(fis); /************************************************************************************************/ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/x-msdownload"); response.setHeader("Content-Disposition", "attachment;filename="+newUser.getFilename());*/ OutputStream os = response.getOutputStream(); byte[] b = new byte[1024]; int len; while ((len=fis.read(b))!=-1) { os.write(b, 0, len); } os.flush(); fis.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return "download";}
基于struts2的的下载
* 动作类action中的download(),代码如下:public String download(){ //path为文件存放路径,newUser.getFilename为对应文件的文件名 FileInputStream fis = new FileInputStream(new File(path,newUser.getFilename())); //newUser为javabean的实例对象 newUser.setInputStreamxxx(fis);return "download";}
* 在javabean中,新增一个属性:inputStream类型的。用于下载获取文件流* 在struts.xml文件,配置如下:<!-- 用于下载 --><result name="download" type="stream"><!-- 对应web中下载配置:application/x-msdownload --><param name="contentType">application/x-msdownload</param> <!-- 对应javabean中inputStream类型的变量的名称--> <param name="inputName">inputStreamxxx</param> <!-- 对应web中下载配置:response.setHeader("Content-Disposition", "attachment;filename="+newUser.getFilename()); --> <param name="contentDisposition">attachment;filename=${filename}</param> <!-- 对应web中下载配置:byte[] b = new byte[1024]; --> <param name="bufferSize">1024</param> </result>
0 0
- struts2下载文件示例
- struts2文件下载示例
- Struts2文件下载的简单示例
- Struts2(多)文件上传和下载使用示例
- Struts2(多)文件上传和下载使用示例
- struts2----一个通用的文件下载代码示例
- Struts2(多)文件上传和下载使用示例
- Struts2上传文件示例
- struts2上传文件示例
- Struts2上传文件示例
- struts2 上传和下载示例
- WinInet 下载文件示例
- WinInet 下载文件示例
- PHP文件下载示例
- 文件下载示例
- Netty示例:文件下载
- springmvc下载文件示例
- struts2实现文件下载
- C++大随机整数的产生,排序和查找
- 关于 C语言中typedef struct 和 struct
- 将php数组或者对象传递给javascript的方法
- hdu 1213:How Many Tables
- C语言中的int类型的范围是由什么决定的
- struts2文件下载示例
- Maven 及其在Eclipse 中的插件的安装
- Oracle 11g各种服务作用以及哪些需要开启
- 空间配置器
- hdu 1232:畅通工程
- ubuntu常用软件安装
- DataGridView合并表头实现 、二维表头的实现
- TCP长连接深入理解
- linux之UDP网络编程