struts2多文件上传

来源:互联网 发布:后期视频制作软件 编辑:程序博客网 时间:2024/05/29 19:15

多文件上传的原理与单文件上传是一样的。

但要注意:

1.jsp中多个input标签内的名字必须一致。

<form action="user/newFileUpMore" method="post" enctype="multipart/form-data">    <input type="file" name="newFileUpMore"/>    <input type="file" name="newFileUpMore"/>    <input type="file" name="newFileUpMore"/>    <input type="submit" value="上传"></form>
2.action接收数据要用数组

private File[] newFileUpMore;private String[] newFileUpMoreContentType;private String[] newFileUpMoreFileName;//这里省略它们的get和set方法文件上传<pre name="code" class="html">public String upMoreFile() {String realPath=ServletActionContext.getServletContext().getRealPath("/image");File file=new File(realPath);if(!file.exists()) {file.mkdirs();}try {for(int i=0; i<newFileUpMore.length; i++) {FileUtils.copyFile(newFileUpMore[i], new File(file,newFileUpMoreFileName[i]));}} catch (IOException e) {e.printStackTrace();}return "success";}




0 0
原创粉丝点击