[ACCEPTED]-Getting server address and application name-jmx

Accepted answer
Score: 32

The HttpServletRequest object will give you what you need:

  • HttpServletRequest#getLocalAddr(): The server's IP address as a string
  • HttpServletRequest#getLocalName(): The name of the server receiving the request
  • HttpServletRequest#getServerName(): The name of the server that the request was sent to
  • HtppServletRequest#getLocalPort(): The port the server received the request on
  • HttpServletRequest#getServerPort(): The port the request was sent to
  • HttpServletRequest#getContextPath(): The part of the path that identifies the application

0

Score: 3

Inside a servlet you can get it like this

public static String getUrl(HttpServletRequest request) {
    return request.getRequestURL().toString();
}

0

More Related questions