J2ee之获取当前域名basepath

需求:

当有二级域名或者通过前置机路由那么需要获取其访问的真实bathpath

实现:

protected String getBasePath(HttpServletRequest request) {
	StringBuffer url = request.getRequestURL();
	String basePath = url
			.delete(url.length() - request.getRequestURI().length(),
					url.length()).append("/").toString();
	return basePath;
}

 

你可能感兴趣的:(J2EE)