获取域名,如: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();
文章详细参考:http://f0rb.iteye.com/blog/1253746