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/

posted @ 2016-07-25 08:55  钟政123  阅读(1475)  评论(0编辑  收藏  举报