拼装当前网页的相对路径
语句格式(形如)
String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
.
.
<html>
<head>
<base href="<%=basePath%>">
</head>
<body>
</body>
</html>
其作用:
是用来表明当前页面的相对路径所使用的根路径的。比如,页面内部有一个连接,完整的路径应该是 http://localhost:80/myblog/authen/login.do其中http://server/是服务器的基本路径,myblog是当前应用程序的名字,那么,我的根路径应该是那么http://localhost:80/myblog/。有了这个-
request.getSchema()可以返回当前页面使用的协议,
-
http”request.getServerName()可以返回当前页面所在的服务器的名字,
-
localhost"request.getServerPort()可以- 返回当前页面所在的服务器使用的端口
-
request.getContextPath()可以返回当前页面所在的应用的名字
转自:https://blog.csdn.net/huaishitou/article/details/41745473