Struts2多文件上传只需要将 单文件上传中的File变成File[]  即可,上篇文章:单文件上传

<form action="${pageContext.request.contextPath}/hello/upload_uploadImage.do" enctype="multipart/form-data" method="post">
图片1:<input type="file" name="image" /><br/>
图片2:<input type="file" name="image" /><br/>
图片3:<input type="file" name="image" /><br/>
图片4:<input type="file" name="image" /><br/>
<input type="submit" value="上传" />
</form>

action:

public class UploadAction {
private File[] image;
private String[] imageFileName;
private String[] imageContentType;
private String message; public String uploadImage() {
try {
String realPath = ServletActionContext.getServletContext().getRealPath("/images");
File filePath = new File(realPath);
if (!filePath.exists()) {
filePath.mkdirs();
}
System.out.println("文件存放路径:" + realPath);
for(int i=0;i<image.length;i++){
if (image[i] != null) {
System.out.println("文件名:" + imageFileName[i] + ",文件类型:" + imageContentType[i]);
File saveFile = new File(filePath, imageFileName[i]);
FileUtils.copyFile(image[i], saveFile);
}
}
message="文件上传成功!";
} catch (IOException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
return "message";
} public File[] getImage() {
return image;
}
public void setImage(File[] image) {
this.image = image;
} public String[] getImageFileName() {
return imageFileName;
}
public void setImageFileName(String[] imageFileName) {
this.imageFileName = imageFileName;
} public String[] getImageContentType() {
return imageContentType;
}
public void setImageContentType(String[] imageContentType) {
this.imageContentType = imageContentType;
} public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
} }

Struts2 多文件上传的更多相关文章

  1. struts2的文件上传

    在做B/S系统时,通常会涉及到上传文件和下载文件,在没接struts2框架之前,我们都是使用apache下面的commons子项目的FileUpload组件来进行文件的上传,但是那样做的话,代码看起来 ...

  2. jsp\struts1.2\struts2 中文件上传(转)

    jsp\struts1.2\struts2 中文件上传 a.在jsp中简单利用Commons-fileupload组件实现 b.在struts1.2中实现c.在sturts2中实现现在把Code与大家 ...

  3. Struts2+Uploadify文件上传使用详解

    Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示.不过官方提供的实例是php版本的,本文将详细介绍Uploadify在java中的使用,您也可以点击下面的链接进行演示或下 ...

  4. Struts2图片文件上传,判断图片格式和图片大小

    1. 配置Struts2能够上传的最大文件大小 使用Struts2进行文件上传的时候,Struts2默认文件大小最大为2MB,如果要传大一点的文件,就需要修改struts.xml配置文件,重新设置能够 ...

  5. Struts2实现文件上传下载功能(批量上传)

    今天来发布一个使用Struts2上传下载的项目, struts2为文件上传下载提供了好的实现机制, 首先,可以先看一下我的项目截图 关于需要使用的jar包,需要用到commons-fileupload ...

  6. Struts2实现文件上传(四)

    Struts2实现文件上传 配置文件struts.xml <!-- /* * $Id: struts.xml 1364077 2012-07-21 12:57:02Z lukaszlenart ...

  7. Struts2实现文件上传(三)

    Struts2实现文件上传 配置文件web.xml <?xml version="1.0" encoding="UTF-8"?> <web-a ...

  8. Struts2实现文件上传(二)

    Struts2实现文件上传 文件上传页面 file.jsp: <%@ page language="java" import="java.util.*" ...

  9. Struts2实现文件上传(一)

    Struts2实现文件上传 文件上传成功后结果页面 result.jsp: <%@ page language="java" import="java.util.* ...

随机推荐

  1. ES5 object的新函数

    虽然说现在并不是所有的浏览器都已经支持ECMAScript5的新特性,但相比于ECMAScript4而言ECMAScript5被广大浏览器厂商广泛接受,目前主流的浏览器中只有低版本的IE不支持,其它都 ...

  2. 混合使用Azure LB和ILB访问相同web服务(2)

    那么现在开始,我们配置下两台WEB服务器的Internal Load  balancer: 打开Powershell,检查当前两台虚拟机的端点配置: Get-AzureVM  -ServiceName ...

  3. Android学习笔记——Activity的启动和创建

    http://www.cnblogs.com/bastard/archive/2012/04/07/2436262.html Android Activity学习笔记——Activity的启动和创建 ...

  4. 查看实时公网ip

    icanhazip.com 使您在任何地方知道你的公网IP地址 icanhazip.com 使你在任何地方知道你的公网IP地址 icanhazip.com 使你在任何地方知道你的公网IP地址 ican ...

  5. ios控制器modal跳转

    1. http://www.cnblogs.com/smileEvday/archive/2012/05/29/presentModalViewController.html 2012年5月- Pre ...

  6. poj1966Cable TV Network(无向图最小点割集 ISAP+邻接矩阵)

    题目请戳这里 邻接表的ISAP被卡了一天...TLE....终于被卡了...好忧桑啊啊啊... 题目大意:给一张无向图,求最少去掉几个点使图不连通. 题目分析:求无向图的点连通度,拆点建图跑最大流.具 ...

  7. ASP.NET 4.0升级至ASP.NET 4.5需要注意的地方 【转】

    原以为只要在Visual Studio 2012中将每个项目的Target framework设置为.NET Framewor 4.5进行编译,然后在web.config中设置compilation的 ...

  8. WIN7 以下创建cocos2d-x3.0+lua项目

    用命令行生成和执行项目 无需打开VS 配置完环境 CMD执行 cocos new  helloWold   -p com.test -l lua -d E:\cocos2dx 来创建项目 cocos ...

  9. (六)Android中Service通信

    一.启动Service并传递参数 传递参数时只需在startService启动的Intent中传入数据便可,接收参数时可在onStartCommand函数中通过读取第一个参数Intent的内容来实现 ...

  10. 不用css样式表和背景图片实现圆角矩形,超简洁!

    当网站页面的整体布局设计好后,接下来有很多细节的实现是很让人头疼的.其中之一就是圆角矩形的实现. 在网上看了很多圆角矩形的实现方法,基本有两种,一种是用纯css实现,不需要背景图片:另一种是用背景图像 ...