获取域名,如: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.lang.StringBuffer.delete()
该方法将删除这个序列的一个子字符串中的字符。子字符串的开始在指定的start和延伸处的字符索引end - 1或结束的序列,如果不存在这样的字符。如果start等于end,不进行任何更改。
以下是java.lang.StringBuffer.delete()方法的声明:
public StringBuffer delete(int start, int end)
参数
-
start -- This is the beginning index, inclusive.
-
end -- This is the ending index, exclusive.此方法返回此对象
异常
-
StringIndexOutOfBoundsException --如果start为负,大于length()或大于端