1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | protected static String getBaseEnvLinkURL() { String baseEnvLinkURL= null ; HttpServletRequest currentRequest = ((ServletRequestAttributes)RequestContextHolder. currentRequestAttributes()).getRequest(); // lazy about determining protocol but can be done too if (currentRequest.getLocalPort() != 80 ) { baseEnvLinkURL += ":" + currentRequest.getLocalPort(); } if (!StringUtils.isEmpty(currentRequest.getContextPath())) { baseEnvLinkURL += currentRequest.getContextPath(); } return baseEnvLinkURL; } |
Friday, December 12, 2014
Spring Web: Get current request and generate base URL
Just a simple way to generate application's base URL according to the environment context using current request:
Subscribe to:
Posts (Atom)