获得应用的根url

String basePath =request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath();

这其实就是 获得应用的根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等等


【获得应用的根url】转载于:https://www.cnblogs.com/leess/archive/2012/12/18/2823008.html

    推荐阅读