request 获取服务根目录地址

这是常用的request获取服务地址的常用方式。

源请求服务地址:http://localhost/api-server/1/forum/thread/hot_topic?sex=1

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

这个截取结果:http://localhost:80/api-server/

学习的时间不一定要特定安排
原文地址:https://www.cnblogs.com/zhongzheng123/p/5702293.html