Here\'s the scenario.
My Java web application has following path
https://www.mywebsite.com:9443/MyWebApp
Let\'s say there is a JSP
Take a look at the documentation for HttpServletRequest.
In order to build the URL in your example you will need to use:
getScheme()getServerName()getServerPort()getContextPath()Here is a method that will return your example:
public static String getURLWithContextPath(HttpServletRequest request) {
return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
}