I want to get the root url of my web application from one of the servlet.
If I deploy my application in \"www.mydomain.com\" I want to get the root url like \"http:/
public static String getBaseUrl(HttpServletRequest request) {
String scheme = request.getScheme();
String host = request.getServerName();
int port = request.getServerPort();
String contextPath = request.getContextPath();
String baseUrl = scheme + "://" + host + ((("http".equals(scheme) && port == 80) || ("https".equals(scheme) && port == 443)) ? "" : ":" + port) + contextPath;
return baseUrl;
}