Struts2 多文件上传
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 多文件上传的更多相关文章
- struts2的文件上传
		在做B/S系统时,通常会涉及到上传文件和下载文件,在没接struts2框架之前,我们都是使用apache下面的commons子项目的FileUpload组件来进行文件的上传,但是那样做的话,代码看起来 ... 
- jsp\struts1.2\struts2 中文件上传(转)
		jsp\struts1.2\struts2 中文件上传 a.在jsp中简单利用Commons-fileupload组件实现 b.在struts1.2中实现c.在sturts2中实现现在把Code与大家 ... 
- Struts2+Uploadify文件上传使用详解
		Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示.不过官方提供的实例是php版本的,本文将详细介绍Uploadify在java中的使用,您也可以点击下面的链接进行演示或下 ... 
- Struts2图片文件上传,判断图片格式和图片大小
		1. 配置Struts2能够上传的最大文件大小 使用Struts2进行文件上传的时候,Struts2默认文件大小最大为2MB,如果要传大一点的文件,就需要修改struts.xml配置文件,重新设置能够 ... 
- Struts2实现文件上传下载功能(批量上传)
		今天来发布一个使用Struts2上传下载的项目, struts2为文件上传下载提供了好的实现机制, 首先,可以先看一下我的项目截图 关于需要使用的jar包,需要用到commons-fileupload ... 
- Struts2实现文件上传(四)
		Struts2实现文件上传 配置文件struts.xml <!-- /* * $Id: struts.xml 1364077 2012-07-21 12:57:02Z lukaszlenart ... 
- Struts2实现文件上传(三)
		Struts2实现文件上传 配置文件web.xml <?xml version="1.0" encoding="UTF-8"?> <web-a ... 
- Struts2实现文件上传(二)
		Struts2实现文件上传 文件上传页面 file.jsp: <%@ page language="java" import="java.util.*" ... 
- Struts2实现文件上传(一)
		Struts2实现文件上传 文件上传成功后结果页面 result.jsp: <%@ page language="java" import="java.util.* ... 
随机推荐
- 【转载】来自苹果的编程语言——Swift简介
			本文转自Lucida的博客 (新浪微博.豆瓣) 这篇文章简要介绍了苹果于WWDC 2014发布的编程语言——Swift. 前言 在这里我认为有必要提一下Brec Victor的Invent ... 
- 可执行文件(ELF)格式的理解
			摘自http://www.cnblogs.com/xmphoenix/archive/2011/10/23/2221879.html 可执行文件(ELF)格式的理解 ELF(Executable an ... 
- STM32F407VG (三)ADC
			12位ADC是一种逐次逼近型模拟数字转换器. 它有多达19个通道,可測量16个外部和2个内部信号源和VBAT通道.各通道的A/D转换能够单次.连续.扫描或间断模式运行. ADC的结果能够左对齐或右对齐 ... 
- Android解析中国天气网的Json数据
			在Android开发中.一般的APP都是通过获取server端的数据来更新UI.从server获取到的数据能够是Json.它的数据量要比XML要小,这里解析中国天气网上获取的数据,尽管已经不再更新了. ... 
- android xml布局文件属性说明
			android xml布局文件属性说明 [摘]android xml布局文件属性说明 LinearLayout和RelativeLayout 共有属性:java代码中通过btn1关联次控件androi ... 
- [AS3]as3与JS的交互(AS3调用JS)实例说明
			一,AS3 vs JavaScript (1)AS3调用JS 函数: ExternalInterface.(functionName:, arguments): //AS3 Code 属性: 同上,通 ... 
- JqueryUI-2
			本文在于巩固基础 jQuery UI Widgets jQuery UI Widgets控件-Accordion <!DOCTYPE html> <html> <head ... 
- HTML5新特性学习-1
			本文在于巩固基础 新特性:音频的使用 <!DOCTYPE html> <html> <head lang="en"> <meta char ... 
- struts 2 debug标签隐藏不显示
			struts2 的标签debug在页面中应用,并且struts的配置文件中也设置为开发模式,但是这个标签却被隐藏了,究其原因,是因为页面中body元素生命了class,其样式覆盖了原来的样式. 比如: ... 
- java中获取类加载路径和项目根路径的5种方法
			import java.io.File; import java.io.IOException; import java.net.URL; public class MyUrlDemo { publi ... 
