String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getSer

这其实就是 获得应用的根url,比如说你的应用的根路径是 http://localhost:8080,那么你列出的代码就是为basePath赋值为 http://localhost:8080
具体点:
1、request.getScheme() 返回协议的名称 http,和后面的"://" 拼起来就成了 http://
2、request.getServerName() 这是获取你的服务器的名称,如果你的应用部署在本机那么其就返回localhost或者127.0.0.1 ,这2个是等价的
3、request.getServerPort() 是你应用使用的端口,比如8080或者80 等等

上面3点的结果拼起来就构成了你应用的根路径或者说是根url

这个是我自己获取程序地址的方法:

request.setAttribute("basePath", request.getScheme() + "://"             + request.getServerName() + ":" + request.getServerPort()             + request.getContextPath() + "/");

basepath的 属性为程序地址

原文地址:https://www.cnblogs.com/gredswsh/p/request_getScheme.html