java request 获取域名

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();  

文章详细参考:http://f0rb.iteye.com/blog/1253746



欢迎大家访问我的个人网站 萌萌的IT人

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