计算upload路径

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ZHOU_VIP/article/details/82856120
/**
 * 计算upload路径
 * 
 * @param request
 * @return
 */
private String getUploadPath(HttpServletRequest request){
	String realPath = request.getSession().getServletContext().getRealPath(request.getRequestURI());
	String basePath = request.getContextPath();
	basePath = basePath.replaceAll("/", "");
	logger.info("realPath="+realPath+", basePath="+basePath);
	int index = realPath.indexOf(basePath);
	if(index >= 0){
		realPath = realPath.substring(0, index);
	}
	realPath = realPath.replaceAll("\\\\", "/");
	if(!realPath.endsWith("/")){
		realPath = realPath + "/";
	}
	String filePath = realPath+"tmpUpload/";
	File f = new File(filePath);
	if(f.exists() == false){
		f.mkdirs();
	}
	f = null;
	return filePath;
}

猜你喜欢

转载自blog.csdn.net/ZHOU_VIP/article/details/82856120