【Java】request.getContextPath()备忘

来源:互联网 发布:淘宝卖家联系客服电话 编辑:程序博客网 时间:2024/06/05 11:11
  1. String path = request.getContextPath();  
  2. String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;  

request.getScheme()可以返回当前页面使用的协议;默认返回http,SSL时返回https;
request.getServerName()可以返回当前页面所在的服务器的名字;
request.getServerPort()可以返回当前页面所在的服务器使用的端口,就是项目在服务器上发布的 端口,或者在本地tomcat容器运行时发布的端口,我用的是8081;
request.getContextPath()可以返回当前页面所在的应用的名字;
原创粉丝点击