首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

struts2下传文件活动文件名、类型

2012-08-26 
struts2上传文件活动文件名、类型public class FileUpload {private File image//获取上传文件private Str

struts2上传文件活动文件名、类型
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"; 
    } 
}

热点排行