Struts2自学入门(十)——多文件上传及文件下载
来源:互联网 发布:002174 游族网络 编辑:程序博客网 时间:2024/06/06 09:04
一、多文件上传
struts.xml
<action name ="uploads" class="com.java1234.action.FileUploadAction"><result name="success">/success.jsp</result><result name="input">/upload.jsp</result></action>
前台页面:
<form action="uploads" method="post" enctype="multipart/form-data">文件1:<input type="file" name="java1234"/><br>文件2:<input type="file" name="java1234"/><br>文件3:<input type="file" name="java1234"/><br><input type ="submit" value="提交"/></form>
package com.java1234.action;import java.io.File;import java.io.FileInputStream;import java.io.InputStream;import java.io.UnsupportedEncodingException;import com.opensymphony.xwork2.ActionSupport;public class FileDownloadAction extends ActionSupport {/** * */private static final long serialVersionUID = 1L;private String fileName;public String getFileName() {try {fileName=new String(fileName.getBytes(),"ISO8859-1");} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();}return fileName;}public void setFileName(String fileName) {this.fileName = fileName;}public static long getSerialversionuid() {return serialVersionUID;}public InputStream getInputStream() throws Exception{File file = new File("D:/高孔威简历.doc");this.fileName="高孔威简历.doc";return new FileInputStream(file);}@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubreturn super.execute();}}
二、文件下载
struts.xml:
<action name ="download" class="com.java1234.action.FileDownloadAction"><result type="stream"><param name="contentDisposition">attachment;filename=${fileName}</param></result></action>
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">其中:
<result type="stream"><param name="contentDisposition">attachment;filename=${fileName}</param></result>
type="stream" 定义了文件是以数据流的形式传到页面的
<param> 配置了下载的文件名
Action:
package com.java1234.action;import java.io.File;import java.io.FileInputStream;import java.io.InputStream;import java.io.UnsupportedEncodingException;import com.opensymphony.xwork2.ActionSupport;public class FileDownloadAction extends ActionSupport {/** * */private static final long serialVersionUID = 1L;private String fileName;public String getFileName() {try {fileName=new String(fileName.getBytes(),"ISO8859-1");} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();}return fileName;}public void setFileName(String fileName) {this.fileName = fileName;}public static long getSerialversionuid() {return serialVersionUID;}public InputStream getInputStream() throws Exception{File file = new File("D:/高孔威简历.doc");this.fileName="高孔威简历.doc";return new FileInputStream(file);}@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubreturn super.execute();}}
前台页面:
<a href="download">文件下载</a>
0 0
- Struts2自学入门(十)——多文件上传及文件下载
- Struts2自学入门(九)——文件上传
- struts2文件上传(多文件)文件下载
- Spring整合Struts2实现多文件上传及下载
- 框架(一)struts2——文件上传与下载
- 走进Struts2(六)— 文件上传和下载
- Struts2学习(八)—文件上传和下载
- struts2文件上传 下载
- Struts2 文件上传 下载
- struts2自学第二课-struts2文件上传
- (十)struts2之文件上传
- Struts2上传与下载(二)- 多文件上传
- struts2自学第三课-struts2文件下载
- Struts2.0之类输入校验篇十(文件的上传和下载续)
- STRUTS2多文件上传以及下载
- struts2 多文件上传与下载
- Struts2 文件上传,下载,删除(四十一)
- 文件上传与下载(一)struts2
- 阿里一道机器人面试题。
- ADO.NET
- 指针和const
- WebServiece实现天气预报
- POJ3278(BFS广度优先搜索)之Catch That Cow
- Struts2自学入门(十)——多文件上传及文件下载
- 【面经】完美世界一面
- 优秀的编程风格(Java篇)
- 模拟御泥坊点击item进入后显示轮播图片
- Java中Integer的最大值和最小值
- javascript中对象创建方式
- C语言小程序—实现strlen等字符串函数
- ASP.NET MVC分页
- Multiple dex files define Lcom/umeng/socialize/PlatformConfig$Platform;