You do realize that the URL client sees (and/or types into his browser) and the URL served by the container your servlet is deployed on can be very different?
In order to get the latter, though, you have a few methods available on HttpServletRequest:
- You can either call
getScheme(),getServerName(),getServerPort()andgetContextPath()and combine them using appropriate separators - OR you can call
getRequestURL()and removegetServletPath()andgetPathInfo()from it.