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. Oracle 修改密码 解锁

    1.怎么修改oracle用户密码 在以SYSDBA身份登陆时可以修改其他用户的密码,比如: SQL> alter user 用户名 identified by 新密码; 用户已更改. 这个是把U ...

  2. Single NumberII

    **一定要注意 == 运算符的优先级高于& 因此在条件判断的时候 必须加括号 class Solution { public: int IsBit1(int num, int place) { ...

  3. 最新首发Eclipse+CDT+android-ndk写纯c++安卓应用(附openGL Es)

    首先下载eclipse和cdt.我的版本依次是:Version: Indigo Service Release 2和Version: 1.0.0.201202111925,再下载windows的ndk ...

  4. 手机端页面自适应:rem布局

    rem布局非常简单,首页你只需在页面引入这段原生js代码就可以了 (function (doc, win) { var docEl = doc.documentElement, resizeEvt = ...

  5. 搭建MyBatis框架

    一.开发环境 1.JDK 1.6.0_22 2.MyEclipse 10.7.1 3.Oracle_10g_10.2.0.4 注:各软件版本不是必须的,正常任意版本都行,文件较大就不附上下载地址了,推 ...

  6. Silverlight学习(三)

    最近对WCFRIA+MVVM+Prism有了初步的认识,能够简单的实现一些数据库的交互.这节主要讲的是Silverlight通过domainservice和ado.net实体数据模型与数据库的交互.本 ...

  7. 【JS】导出table到excel,同时兼容FF和IE

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. 关于C语言指针几个容易混淆的概念

    前言: 大多数学习过C/C++或者正在学习的同学在对指针概念把握时,总是感觉不太明了,小弟我也不例外啊,于是翻开资料复习整理一下,并把自己的学习心得拿出来供大家分享,讨论. 基本概念掠过,主要来探讨一 ...

  9. C++_String

    String -String的实现 -String常用操作

  10. golang Rsa

    package models import ( "crypto/rand" "crypto/rsa" "crypto/x509" " ...