Skip to content

Instantly share code, notes, and snippets.

@beradrian
Last active April 18, 2024 23:45
Show Gist options
  • Save beradrian/d66008b6c5a784185c29 to your computer and use it in GitHub Desktop.
Save beradrian/d66008b6c5a784185c29 to your computer and use it in GitHub Desktop.
Get baseUrl for a servlet request
String getBaseUrl(HttpServletRequest request) {
String baseUrl = request.getRequestURL().substring(0, request.getRequestURL().length() - request.getRequestURI().length()) + request.getContextPath();
return baseUrl;
}
@axelrindle
Copy link

👍

@andredvb
Copy link

Awesome job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment