Struts2 多文件上传
来源:互联网 发布:淘宝工作室是做什么 编辑:程序博客网 时间:2024/06/13 03:50
在 struts.xml 中:
<struts><constant name="struts.multipart.maxSize=5242880" ></constant>#控制最大缓存值<package name="upload" namespace="/upload" extends="struts-default"><action name="upload2" class="cn.itcast.action.UploadAction2" method="execute"><result name="success">/success.jsp</result></action></package></struts>
在 UploadAction2 中:
public class UploadAction2 extends ActionSupport implements Serializable{private File[] image;// 对应的就是表单中文件上传的那个输入域的名称,Struts2框架会封装成File类型private String[] imageFileName;// 上传输入域 FileName 即文件名private String[] imageContentType;// 文件上传的MIME类型封装……public String execute(){try{if( image!=null && images.length >0){ServletContext sc = ServletActionContext.getServletContext();String storePath = sc.getRealPath("/files");for(int i =0; i<images.length; i++){FileUtils.copyFile( image[i], new File(storePath, imageFileName[i]) );}}ActionContext.getContext().put("message","上传成功");return SUCCESS;} catch(Exception e){return ERROR;}}}
在上传页面 upload2.jsp 中
<form action="${pageContext.request.contextPath}/upload/upload2" method="post" enctype="multipart/form-data">文件1:<input type="file" name="image"><br/>文件2:<input type="file" name="image"><br/>文件3:<input type="file" name="image"><br/><input type="submit" value="上传"></form>
0 0
- Struts2多文件上传
- struts2多文件上传
- struts2多文件上传
- struts2 多文件上传
- struts2多文件上传
- struts2多文件上传
- struts2多文件上传
- struts2多文件上传
- Struts2多文件上传
- Struts2多文件上传
- Struts2 多文件上传
- struts2多文件上传
- struts2 多文件上传
- Struts2多文件上传
- struts2多文件上传
- struts2 多文件上传
- struts2多文件上传
- struts2多文件上传
- 稀疏矩阵ADT_SeqTriple
- JAVA基础--db17_javaMap集合_集合框架工具类
- Max Points on a Line
- 面试算法题
- 安卓控件使用系列1:TextView显示各种格式的文本
- Struts2 多文件上传
- socket套接字编程函数
- JavaScript之浏览器兼容问题
- 转载:iOS开发的一些奇巧淫技
- CodeForces 2A Winner(CodeForces的题意总是那么难理解)——Codeforces Beta Round #2
- 习题6-11 树重建 UVa 10410 *
- 复制构造函数跟赋值构造函数的区别
- IOS中Json解析的四种方法
- 金山词霸2016 代理设置 方法