2.struts上传多个文件
来源:互联网 发布:软件技术服务合同范本 编辑:程序博客网 时间:2024/04/29 17:35
使用struts的标签库:
<body><s:form action="/uploadList.action" enctype="multipart/form-data" method="post"><s:textfield label="文件名称" name="name"></s:textfield><s:file label="选择文件" name="upload"></s:file><s:file label="选择文件" name="upload"></s:file><s:file label="选择文件" name="upload"></s:file><s:submit value="上传"/></s:form> </body>
记得加标签:
<%@ taglib uri="/struts-tags" prefix="s"%>
struts的配置文件:
<?xml version="1.0" encoding="GBK"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.multipart.maxSize" value="409715200" /> <package name="struct2" extends="struts-default"> <action name="uploadList" class="struct2.uploadFile"> <result>../success.jsp</result> <result name="input">../tagUpload.jsp</result> <interceptor-ref name="fileUpload"> <param name="allowedTypes">image/bmp,image/x-png,image/gif</param> <param name="maximumSize">4M</param> </interceptor-ref> <interceptor-ref name="defaultStack"></interceptor-ref> </action> </package> </struts>
<constant name="struts.multipart.maxSize" value="409715200" /> //修改默认的最大上传文件的限度<pre name="code" class="html"><param name="maximumSize">4M</param>//限定文件大小,大小不大于上面的
action的处理过程:
package struct2;import java.io.File;import java.io.IOException;import java.util.List;import org.apache.commons.io.FileUtils;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;public class uploadFile extends ActionSupport {private static final long serialVersionUID = 1L;private String name;private List<File> upload;//文件集合private List<String> uploadContextType;//文件类型集合private List<String> uploadFileName;//上传文件的名称public String getName() {return name;}public void setName(String name) {this.name = name;}public List<File> getUpload() {return upload;}public void setUpload(List<File> upload) {this.upload = upload;}public List<String> getUploadContextType() {return uploadContextType;}public void setUploadContextType(List<String> uploadContextType) {this.uploadContextType = uploadContextType;}public List<String> getUploadFileName() {return uploadFileName;}public void setUploadFileName(List<String> uploadFileName) {this.uploadFileName = uploadFileName;}public String execute(){String path = ServletActionContext.getServletContext().getRealPath("/WEB-INF/uploadList");File file = new File(path);if(!file.exists()){file.mkdirs();//不存在时创建,养成好的习惯,每次检验文件呀是否存在(即使你已经创建)}for(int i=0;i<upload.size();i++){try {FileUtils.copyFile(upload.get(i), new File(file,uploadFileName.get(i))); return SUCCESS; } catch (IOException e) {e.printStackTrace();}}return null;}}
0 0
- 2.struts上传多个文件
- struts多个文件上传。
- Struts多个文件上传
- 用Struts上传多个文件
- struts实现多个文件上传功能
- struts中上传多个文件
- struts+hibernate实现多个文件上传
- struts上传任意多个文件
- Struts单、多个文件的上传
- Struts文件上传--2.多文件上传
- struts 多文件上传--多个文件的name问题
- Struts 多个文件,拦截器,文件上传
- struts 多文件上传
- struts多文件上传
- Struts多文件上传
- 用Struts上传多个文件的方法
- 用struts上传多个文件的方法
- 用struts上传多个文件的方法
- 第五章知识回顾
- 2014.12.07 BBC Leaning English
- DEM的三维地形在地理坐标系和投影坐标系中的表现
- javascript字符串转化成数字
- sgu111高精度开方
- 2.struts上传多个文件
- 数据结构之树
- 黑马程序员之IOS学习总结——03C语言中循环结构
- RPG游戏学习——3.rpgmaker事件学习2
- VMware View 5.0 安装总结(No View Composer server found. )
- 表结构设计器(EZDML)1.99版发布
- hdu-1548
- 6个值得推荐的Android开源框架
- Java synchronized详解