获得应用的根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
推荐阅读
- Docker应用:容器间通信与Mariadb数据库主从复制
- JS中的各种宽高度定义及其应用
- 陇上秋二|陇上秋二 罗敷媚
- 异地恋中,逐渐适应一个人到底意味着什么()
- 我们应该和什么样的人交朋友
- (七)谈条件
- 为什么985/211的学生能胜任工作获得老板的青睐。
- 早知道你是只飞鸟,我就应该把你关起来
- 《老婆》
- 每天都应该是新的开始