用到的代码如下:
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
解释:
request.getContextPath()
其作用是获取当前的系统路径。
request.getSchema() 返回当前页面使用的协议,http 或是 https;
request.getServerName() 返回当前页面所在的服务器的名字;
request.getServerPort() 返回当前页面所在的服务器使用的端口,就是80;
request.getContextPath() 返回当前页面所在的应用的名字;
总结:
就是为了获取项目中页面的地址
本文介绍了一种在Java Web应用中获取当前页面完整URL的方法,包括协议、服务器名称、端口号及应用名称等组成部分。
282

被折叠的 条评论
为什么被折叠?



