Skip to content

Instantly share code, notes, and snippets.

@jeffersonchaves
Created September 16, 2021 18:18
Show Gist options
  • Save jeffersonchaves/3f0a74db2af7ffc4f70cf7346bd7a999 to your computer and use it in GitHub Desktop.
Save jeffersonchaves/3f0a74db2af7ffc4f70cf7346bd7a999 to your computer and use it in GitHub Desktop.
Servlet Base Path Snippet
String getBaseUrl(HttpServletRequest request) {
String baseUrl = request.getRequestURL().substring(0, request.getRequestURL().length() - request.getRequestURI().length()) + request.getContextPath();
return baseUrl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment