package com.zsj.struts2.fileupload.action;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class FileUploadAction extends ActionSupport {
private File userImage;
private String userImageContentType;
private String userImageFileName;
@Override
public String execute() throws Exception {
String pathname = ServletActionContext.getServletContext().getRealPath("/p_w_picpaths");
File destFile = new File(pathname );
if(!destFile.getParentFile().exists()){
destFile.getParentFile().mkdirs();
FileUtils.copyFile(userImage, destFile );
}
return super.execute();
}
public File getUserImage() {
return userImage;
}
public void setUserImage(File userImage) {
this.userImage = userImage;
}
public String getUserImageContentType() {
return userImageContentType;
}
public void setUserImageContentType(String userImageContentType) {
this.userImageContentType = userImageContentType;
}
public String getUserImageFileName() {
return userImageFileName;
}
public void setUserImageFileName(String userImageFileName) {
this.userImageFileName = userImageFileName;
}
}
多文件上传,将属性定义为数组就好,如File p_w_picpath[]
转载于:https://blog.51cto.com/xxzjzsj/1340591