package action;
import java.io.*;
import java.util.Date;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
public class Test{
private File image;
public Test() {
super();
// TODO Auto-generated constructor stub
}
public File getImage() {
return image;
}
public void setImage(File image) {
this.image = image;
}
public String execute() throws IOException {
System.out.println(this.image.getPath());
System.out.println("hello");
String fileName =new Date().getTime()+".jpg";
String path =ServletActionContext.getRequest().getRealPath("upload/");
System.out.println(path);
//String fileName =new Date().getTime()+str;
System.out.println(path+"/"+fileName);
FileUtils.copyFile(image, new File(path+"/"+fileName));
return null;
}
}
struts上传文件
最新推荐文章于 2024-04-19 21:01:24 发布