struts上传文件

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上传文件)