Java Request 获取域名

获取域名,如:http://f0rb.iteye.com/
StringBuffer url = request.getRequestURL();
String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append("/").toString();


获取带部署环境上下文的域名,如: http://www.iteye.com/admin/
StringBuffer url = request.getRequestURL();
String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append(request.getServletContext().getContextPath()).append("/").toString();

你可能感兴趣的:(java,request,域名)