public static String geServerBaseURL(HttpServletRequest request){
  String uri=request.getRequestURI();
  int index=uri.indexOf("/",1);
  if (index != -1) {
    uri=uri.substring(0,index);
  }
  return request.getScheme() + "://" + request.getServerName()+ ":"+ request.getServerPort()+ uri;
}

public static String geServerBaseURL ( HttpServletRequest request ) { String uri = request . getRequestURI ( ) ; int index = uri . indexOf ( "/" , 1 ) ; if ( index != - 1 ) { uri = uri . substring ( 0 , index ) ; } return request . getScheme ( ) + "://" + request . getServerName ( ) + ":" + request . getServerPort ( ) + uri ; }
returns base url for the server , the url contains the protocol , server name , server port and deployment uri . for example : http : / / www . sun . com : 80 / amserver
