通过request获取域名,请求路径,端口号等
HttpServletRequest request = getRequest();
String scheme = request.getScheme();//http
String serverName = request.getServerName();//localhost
int serverPort = request.getServerPort();//8080
String contextPath = request.getContextPath();//项目名
String url = scheme+"://"+serverName+":"+serverPort+contextPath;//http://127.0.0.1:8080/test
原文:https://www.cnblogs.com/xxlfly/p/14557760.html