package com.hutu.util;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class BatchUpload extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 2160200185775231663L;
private File[] file;//接收上传的文件
private String[] fileFileName;//struts2提供的格式,在文件名后面+FileName就是上传文件的名字
private String[] fileContentType;
public File[] getFile() {
return file;
}
public void setFile(File[] file) {
this.file = file;
}
public String[] getFileFileName() {
return fileFileName;
}
public void setFileFileName(String[] fileFileName) {
this.fileFileName = fileFileName;
}
public String[] getFileContentType() {
return fileContentType;
}
public void setFileContentType(String[] fileContentType) {
this.fileContentType = fileContentType;
}
public String bachUpload() {
String realPath = ServletActionContext.getServletContext().getRealPath(
"upload");
if (file != null && file.length > 0) {
for (int i = 0; i < file.length; i++) {
File saveFile = new File(new File(realPath), fileFileName[i]);
if (!saveFile.getParentFile().exists()) {
saveFile.mkdirs();
}
try {
FileUtils.copyFile(file[i], saveFile);
} catch (IOException e) {
e.printStackTrace();
}
}
}
return "success";
}
}