struts2 上传附件 处理

private File picFile;//附件
	
private String picFileFileName; //文件名称   
	
private String picFileContentType; //文件类型

public String add() throws Exception{
		
		String path = new SimpleDateFormat("yyyyMM").format(new Date())+ "/";
		String tpath = FileUtil.getTomcatPath()+request.getContextPath()+"/images/";
		if (picFile != null) {            
			File savefile = new File(new File(tpath+path),picFileFileName);            
			if (!savefile.getParentFile().exists())                
				savefile.getParentFile().mkdirs();            
			FileUtil.copyFile(picFile, savefile);            
		}    

}

猜你喜欢

转载自ch-dj.iteye.com/blog/1894167
今日推荐