Created
May 30, 2023 13:18
-
-
Save levancho/388bda22da1bb7200e77e9ad1dca76d9 to your computer and use it in GitHub Desktop.
get url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getURL(HttpServletRequest curRequest) { | |
if(curRequest ==null) { | |
return "https://treespond.com/"; | |
} | |
String scheme = curRequest.getScheme(); // http | |
String serverName = curRequest .getServerName(); // hostname.com | |
int serverPort = curRequest .getServerPort(); // 80 | |
String contextPath = curRequest .getContextPath(); // /mywebapp | |
String servletPath = curRequest.getServletPath(); // /servlet/MyServlet | |
String pathInfo = curRequest .getPathInfo(); // /a/b;c=123 | |
StringBuffer sb = new StringBuffer() ; | |
// if(serverName !=null && serverName.equalsIgnoreCase("spingun.com")){ | |
// scheme="https"; | |
// } | |
sb.append(scheme) ; | |
sb.append("://") ; | |
sb.append(serverName) ; | |
if(serverPort!=80 && serverPort!=443) { | |
sb.append(":") ; | |
sb.append(serverPort) ; | |
} | |
sb.append(contextPath) ; | |
return sb.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment