public class FileUpload {
private File image;//获取上传文件
private String imageFileName;//获取上传文件名称
private String imageContentType;//获取上传文件类型
public String getImageContentType() {
return imageContentType;
}
public void setImageContentType(String imageContentType) {
this.imageContentType = imageContentType;
}
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 execute(){
String path = ServletActionContext.getServletContext().getRealPath("/images");
System.out.println(path);
if(image != null){
File savefile = new File(new File(path),imageFileName);
if(!savefile.getParentFile().exists())
savefile.getParentFile().mkdirs();
try {
FileUtils.copyFile(image , savefile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] t = imageContentType.split("/");
for(String s : t)
System.out.println(s);
}
return "success";
}
}
private File image;//获取上传文件
private String imageFileName;//获取上传文件名称
private String imageContentType;//获取上传文件类型
public String getImageContentType() {
return imageContentType;
}
public void setImageContentType(String imageContentType) {
this.imageContentType = imageContentType;
}
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 execute(){
String path = ServletActionContext.getServletContext().getRealPath("/images");
System.out.println(path);
if(image != null){
File savefile = new File(new File(path),imageFileName);
if(!savefile.getParentFile().exists())
savefile.getParentFile().mkdirs();
try {
FileUtils.copyFile(image , savefile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] t = imageContentType.split("/");
for(String s : t)
System.out.println(s);
}
return "success";
}
}